-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
116 lines (103 loc) · 3.25 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
const gulp = require('gulp'),
del = require('del'),
seqRunner = require('run-sequence'),
uglify = require('gulp-uglify-es').default,
webpack = require('webpack-stream'),
compiler = require('webpack'),
rename = require('gulp-rename'),
prettier = require('gulp-prettier'),
minifyHTML = require('gulp-htmlmin'),
minifyCSS = require('gulp-cssmin'),
minifyIMG = require('gulp-imagemin')
gulp.task('clean', () => {
return del('./pkg', {
force: true
});
});
gulp.task('pack-dependencies', () => {
gulp.src('./src/assets/js/*').pipe(gulp.dest('./pkg/assets/js'));
return gulp.src('./src/assets/css/*').pipe(gulp.dest('./pkg/assets/css'));
});
gulp.task('js-pretty', () => {
return gulp.src('./src/scripts/**/*.js')
.pipe(prettier({
singleQuote: true
}))
.pipe(gulp.dest('./src/scripts'));
});
gulp.task('bundle-scripts-assistant', () => {
return gulp.src('./src/scripts/**/*.js')
.pipe(webpack({
mode: 'development'
}, compiler))
.pipe(uglify({
output: {
max_line_len: 80
}
}))
.pipe(rename('assistant.js'))
.pipe(gulp.dest('./pkg/scripts'));
});
gulp.task('bundle-scripts-background', () => {
return gulp.src('./src/scripts/background/**/*.js')
.pipe(webpack({
mode: 'development'
}, compiler))
.pipe(uglify({
output: {
max_line_len: 80
}
}))
.pipe(rename('background.js'))
.pipe(gulp.dest('./pkg/scripts'));
});
gulp.task('bundle-styles', () => {
return gulp.src('./src/styles/*')
.pipe(minifyCSS())
.pipe(gulp.dest('./pkg/styles'));
});
gulp.task('bundle-remain', () => {
return gulp.src('./src/manifest.json')
.pipe(gulp.dest('./pkg'));
});
gulp.task('bundle-views', () => {
return gulp.src('./src/ui/**/*')
.pipe(minifyHTML({
collapseWhitespace: true
}))
.pipe(gulp.dest('./pkg/ui'));
});
gulp.task('bundle-images', () => {
return gulp.src('./src/assets/img/*')
.pipe(minifyIMG())
.pipe(gulp.dest('pkg/assets/img'));
});
gulp.task('build', () => {
seqRunner('clean', 'js-pretty', 'bundle-scripts-background', [
'pack-dependencies',
'bundle-scripts-assistant',
'bundle-views',
'bundle-remain',
'bundle-styles',
'bundle-images'
]);
});
gulp.task('run', ['pack-dependencies', 'bundle-scripts', 'bundle-remain', 'bundle-views', 'bundle-styles']);
gulp.task('watch', () => {
seqRunner('clean', 'js-pretty', 'bundle-scripts-background', [
'pack-dependencies',
'bundle-scripts-assistant',
'bundle-views',
'bundle-remain',
'bundle-styles',
'bundle-images'
]);
gulp.watch('./src/assets/js/*',['pack-dependencies']);
gulp.watch('./src/scripts/assistant/**/*.js', ['bundle-scripts-assistant']);
gulp.watch('./src/scripts/background/**/*.js', ['bundle-scripts-background']);
gulp.watch('./src/manifest.json', ['bundle-remain']);
gulp.watch('./src/ui/**/*', ['bundle-views']);
gulp.watch('./src/styles/*', ['bundle-styles']);
gulp.watch('./src/assets/img/*', ['bundle-images']);
});
gulp.task('default', ['run', 'watch']);