forked from AlicanC/jsgif
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
65 lines (56 loc) · 1.43 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
const gulp = require('gulp');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gutil = require('gulp-util');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const browserify = require('browserify');
const babelify = require('babelify');
const fse = require('fs-extra');
const babel = require('gulp-babel');
function cleanCommonJs(callback) {
fse.emptyDir('./dist/commonjs/', callback);
}
function cleanBundle(callback) {
fse.emptyDir('./dist/bundle/', callback);
}
function buildCommonJs() {
return gulp.src([
'./src/**/*.js',
'!./src/bundle.js',
])
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/commonjs/'));
}
function buildBundle() {
const b = browserify({
'entries': './src/bundle.js',
'debug': true,
'transform': [babelify]
});
return b.bundle()
.pipe(source('GifEncoder.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/bundle/'));
}
const buildCommonJsTask = gulp.series(
cleanCommonJs,
buildCommonJs
);
const buildBundleTask = gulp.series(
cleanBundle,
buildBundle
);
gulp.task('build', gulp.parallel(
buildCommonJsTask,
buildBundleTask
));
gulp.task('watch', () => {
gulp.watch('./src/**/*.js', buildBundleTask);
});