-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGulpfile.js
More file actions
95 lines (81 loc) · 2.7 KB
/
Gulpfile.js
File metadata and controls
95 lines (81 loc) · 2.7 KB
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
var browserify = require("browserify");
const gulp = require("gulp");
const uglify = require("gulp-uglify");
const del = require("del");
const ts = require("gulp-typescript");
const source = require("vinyl-source-stream");
const zip = require("gulp-zip");
const { dest } = require("gulp");
const paths = {
license: ["LICENSE"],
sources: ["src/*"],
ts: ["src/*.ts"],
static: ["src/*.html", "src/*.css", "src/manifest.json", "src/*.png"],
styles: ["src/*.scss"],
intermediate: "build/tmp",
output: "build",
};
function clean() {
return del(["build/*"]);
}
function transpile() {
return gulp
.src(paths.ts)
.pipe(ts({ noImplicitAny: true }))
.pipe(gulp.dest(paths.intermediate));
}
function bundleBackground() {
return browserify({ entries: [paths.intermediate + "/background.js"] })
.bundle()
.pipe(source("background.js"))
.pipe(gulp.dest(paths.intermediate));
}
function bundleContent() {
return browserify({ entries: [paths.intermediate + "/content.js"] })
.bundle()
.pipe(source("content.js"))
.pipe(gulp.dest(paths.intermediate));
}
function bundlePopup() {
return browserify({ entries: [paths.intermediate + "/popup.js"] })
.bundle()
.pipe(source("popup.js"))
.pipe(gulp.dest(paths.intermediate));
}
function outputScripts() {
return gulp.src([paths.intermediate + "/*.js", "!" + paths.intermediate + "/firebase_config.js"]).pipe(gulp.dest(paths.output));
}
function minify() {
return gulp
.src([paths.intermediate + "/*.js", "!" + paths.intermediate + "/firebase_config.js"])
.pipe(uglify())
.pipe(gulp.dest(paths.output));
}
function cleanTmp() {
return del([paths.intermediate + "/"]);
}
function copyStaticAssets() {
return gulp.src(paths.static).pipe(gulp.dest(paths.output));
}
function copyLicense() {
return gulp.src(paths.license).pipe(gulp.dest(paths.output));
}
function compressArtifacts() {
return gulp
.src(paths.output + "/**")
.pipe(zip("release.zip"))
.pipe(dest(paths.output));
}
// Not all tasks need to use streams.
// A gulpfile is another node program
// and you can use all packages available on npm.
gulp.task("clean", clean);
gulp.task("build", gulp.series("clean", transpile, bundleBackground, bundleContent, bundlePopup, outputScripts, cleanTmp, copyStaticAssets));
gulp.task("watch", () => gulp.watch(paths.sources, gulp.series(["build"])));
gulp.task("minify", gulp.series("clean", transpile, bundleBackground, bundleContent, bundlePopup, minify, cleanTmp, copyStaticAssets));
gulp.task(
"pack",
gulp.series("clean", transpile, bundleBackground, bundleContent, bundlePopup, minify, cleanTmp, copyStaticAssets, copyLicense, compressArtifacts)
);
// The default task (called when you run `gulp` from CLI).
gulp.task("default", gulp.series(["build", "watch"]));