-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
76 lines (63 loc) · 1.85 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
var manifest = require('./package.json');
var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');
var del = require('del');
var webpack = require('gulp-webpack');
var merge = require('gulp-merge-json');
var zip = require('gulp-zip');
function isProduction() {
return process.env.NODE_ENV === 'production';
}
gulp.task('set-production', function() {
return (process.env.NODE_ENV = 'production');
});
gulp.task('set-development', function() {
return (process.env.NODE_ENV = 'development');
});
gulp.task('cleanup', function() {
return del(['package/dist/**/*']);
});
gulp.task('updateVersion', function() {
return gulp
.src('package/manifest.json')
.pipe(
merge({
fileName: 'manifest.json',
endObj: { version: manifest.version },
jsonSpace: ' ',
})
)
.pipe(gulp.dest('package'));
});
gulp.task('webpack', function() {
var webpackPipe;
if (isProduction()) {
webpackPipe = webpack(require('./webpack.prod.js'));
} else {
webpackPipe = webpack(require('./webpack.config.js'));
}
return gulp
.src('src/entry.js')
.pipe(webpackPipe)
.pipe(gulp.dest('package/dist/'));
});
gulp.task('copy', function() {
return gulp.src('src/**/*.html').pipe(gulp.dest('package/dist/'));
});
gulp.task('package', function() {
return gulp
.src('./package/**/*')
.pipe(zip(`${manifest.name}-${manifest.version}.zip`))
.pipe(gulp.dest('./releases'));
});
gulp.task('watch', ['copy', 'webpack'], function() {
gulp.watch('src/**/*.html', ['copy']);
});
gulp.task(
'build',
gulpSequence(['cleanup', 'updateVersion'], ['copy', 'webpack'])
);
gulp.task('development', gulpSequence('set-development', 'watch'));
gulp.task('production', gulpSequence('set-production', 'build'));
gulp.task('publish', gulpSequence('production', 'package'));
gulp.task('default', ['development']);