-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
119 lines (103 loc) · 4.08 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
118
119
'use strict';
var argv = require('yargs')
.usage('Usage: $0 -o [file] -g [globals] task')
.demand(['o'])
.describe('o', 'Output file')
.argv;
var gulp = require('gulp');
var del = require('del');
var util = require('gulp-util');
var rollup = require('rollup-stream');
var uglify = require('gulp-uglify');
var browserSync = require('browser-sync').create();
var nodeResolve = require('rollup-plugin-node-resolve');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var rename = require('gulp-rename');
var commonjs = require('rollup-plugin-commonjs');
var json = require('rollup-plugin-json');
var babel = require('rollup-plugin-babel');
var string = require('rollup-plugin-string');
var outputFilename = argv.o;
var globals = [];
if (argv.g) {
globals = Array.isArray(argv.g) ? argv.g : [ argv.g ]
}
var skips = [ ];
var globalMap = {};
globals.forEach((d) => {
var target = null;
if (d.indexOf('d3-') === 0) {
target = 'd3';
skips.push(d);
} else {
throw new Error('Unknown global type: ' + d);
}
globalMap[d] = target;
});
var task = {};
gulp.task('clean', () => del([ 'distribution/**' ]));
gulp.task('umd', task.umd = () => {
return rollup({
moduleName: outputFilename.replace(/-/g, '_'),
globals: globalMap,
entry: 'index.js',
format: 'umd',
sourceMap: true,
plugins: [
json({
include: [ '**/package.json', 'tiles/*.json', 'node_modules/**/*.json' ],
exclude: [ ]
}),
string({
include: '**/*.glsl'
}),
nodeResolve({
skip: skips,
// use "jsnext:main" if possible
// – see https://github.com/rollup/rollup/wiki/jsnext:main
jsnext: true, // Default: false
// use "main" field or index.js, even if it's not an ES6 module
// (needs to be converted from CommonJS to ES6
// – see https://github.com/rollup/rollup-plugin-commonjs
main: true, // Default: true
// not all files you want to resolve are .js files
extensions: [ '.js' ], // Default: ['.js']
// whether to prefer built-in modules (e.g. `fs`, `path`) or
// local ones with the same names
preferBuiltins: false // Default: true
}),
commonjs(),
babel({
exclude: ['node_modules/**', 'tiles/**']
})
]
})
.pipe(source('index.js', './src'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(rename({basename: outputFilename}))
.pipe(rename({suffix: '.umd-es2015'}))
.pipe(gulp.dest('distribution/'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('distribution/'));
});
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: [ './examples', './distribution', './tiles' ],
directory: true
}
});
});
gulp.task('serve', ['default', 'browser-sync'], function() {
gulp.watch(['./*.js', './src/*.js', './tiles/grid-lq.json'], [ 'umd' ]);
gulp.watch('./distribution/*.js').on('change', () => browserSync.reload('*.js'));
gulp.watch('./tiles/*.json').on('change', () => browserSync.reload('*.html'));
gulp.watch('./examples/**/*.html').on('change', () => browserSync.reload('*.html'));
});
gulp.task('build', [ 'clean' ], task.umd);
gulp.task('default', [ 'umd' ]);