forked from lichess-org/chessground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
52 lines (44 loc) · 1.33 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
const gulp = require('gulp');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const colors = require('ansi-colors');
const logger = require('fancy-log');
const watchify = require('watchify');
const browserify = require('browserify');
const terser = require('gulp-terser');
const size = require('gulp-size');
const tsify = require('tsify');
const browserifyOpts = (debug) => ({
entries: ['src/index.js'],
standalone: 'Chessground',
debug: debug
});
const destination = () => gulp.dest('./dist');
const prod = () => browserify(browserifyOpts(false))
.plugin(tsify)
.bundle()
.pipe(source('chessground.min.js'))
.pipe(buffer())
.pipe(terser({safari10: true}))
.pipe(size())
.pipe(destination());
const dev = () => browserify(browserifyOpts(true))
.plugin(tsify)
.bundle()
.pipe(source('chessground.js'))
.pipe(destination());
const watch = () => {
const bundle = () => bundler
.bundle()
.on('error', error => logger.error(colors.red(error.message)))
.pipe(source('chessground.js'))
.pipe(destination());
const bundler = watchify(
browserify(Object.assign({}, watchify.args, browserifyOpts(true)))
.plugin(tsify)
).on('update', bundle).on('log', logger.info);
return bundle();
};
gulp.task('prod', prod);
gulp.task('dev', dev);
gulp.task('default', watch);