-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
34 lines (30 loc) · 917 Bytes
/
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
var gulp = require('gulp');
// 生成 sw.js
const workbox = require("workbox-build");
const uglifyes = require('uglify-es');
const composer = require('gulp-uglify/composer');
const uglify = composer(uglifyes, console);
const pipeline = require('readable-stream').pipeline;
gulp.task('generate-service-worker', () => {
return workbox.injectManifest({
swSrc: './sw-template.js',
swDest: './public/sw.js',
globDirectory: './public',
globPatterns: [
"**/*.{html,css,js,json,woff2}"
],
modifyURLPrefix: {
"": "./"
}
});
});
gulp.task("uglify", function () {
return pipeline(
gulp.src("./public/sw.js"),
uglify(),
gulp.dest("./public")
);
});
// 执行 gulp 命令时执行的任务
gulp.task("build", gulp.series("generate-service-worker", "uglify"));
gulp.task("sw-uglify", gulp.series("uglify"));