-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
117 lines (99 loc) · 2.74 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*eslint-disable */
var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');
var rollup = require('rollup');
var babel = require('rollup-plugin-babel');
var browserSync = require('browser-sync');
var compressJs = require('gulp-uglify');
var compressCss = require('gulp-cssnano');
var headerComment = require('gulp-header-comment');
var rimraf = require('gulp-rimraf');
var rename = require('gulp-rename');
var _ = require('underscore');
var reload = browserSync.reload;
var package = require('./package.json');
// Browser
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: ["./docs", "./dev"]
},
files: ['./docs/**/*.*', './dev/**/*.*'],
port: 5000,
});
});
// Watch
gulp.task('watch', function() {
gulp.watch('src/**/*.js', ['build:js:dev']);
gulp.watch('src/*.css', ['build:css:dev']);
});
// Javascript
function buildJs(dest) {
return rollup.rollup({
entry: './src/index.js',
plugins: [
babel({ runtimeHelpers: true })
]
}).then( function ( bundle ) {
return bundle.write({
format: 'iife',
moduleName: 'd3.maptable',
globals: {
d3: 'd3',
topojson: 'topojson'
},
sourceMap: true,
dest: dest + '/maptable.js'
});
})
.then(() => {
return gulp.src([dest + '/maptable.js', dest + '/maptable.css']).pipe(gulp.dest('./docs/'));
})
.then(() => {
return browserSync.reload();
});
}
// Build for distribution
gulp.task('build:js:dist', function() {
return buildJs('./dist');
});
// Build for developmeent environment
gulp.task('build:js:dev', function() {
return buildJs('./dev');
});
// Compression
gulp.task('compress:js', function() {
return gulp.src('dist/*.js')
.pipe(compressJs())
.pipe(headerComment('MapTable '+ package.version + ' - License MIT - Build: ' + (new Date()).toString()))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./docs'));
});
// CSS
function buildCss(dest) {
return gulp.src('./src/*.css')
.pipe(compressCss())
.pipe(gulp.dest(dest))
.pipe(gulp.dest('./docs'))
.pipe(reload({stream:true}));
}
gulp.task('build:css:dev', function() {
return buildCss('./dev');
});
gulp.task('build:css:dist', function() {
return buildCss('./dist');
});
// Clean
gulp.task('clean:js:dist', function() {
return gulp.src('./dist/*.js', { read: false })
.pipe(rimraf({ force: true }));
});
gulp.task('clean:js:dev', function() {
return gulp.src('./dev/*.js', { read: false })
.pipe(rimraf({ force: true }));
});
gulp.task('default', gulpSequence('clean:js:dev', ['build:js:dev', 'build:css:dev'], 'browser-sync', 'watch'));
gulp.task('dist', gulpSequence('clean:js:dist', ['build:js:dist', 'build:css:dist'], 'compress:js'));