This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.babel.js
71 lines (62 loc) · 2.11 KB
/
gulpfile.babel.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
import gulp from "gulp";
import imageResize from "gulp-image-resize";
import jsonminify from "gulp-jsonminify";
import less from "gulp-less";
import minifyCSS from "gulp-minify-css";
import rename from "gulp-rename";
import uglify from "gulp-uglify";
import watch from "gulp-watch";
import browserify from "browserify";
import babelify from "babelify";
import source from "vinyl-source-stream";
import buffer from "vinyl-buffer";
import del from "del";
import runSequence from "run-sequence";
const sourceDir = "src";
const buildDir = "dist";
gulp.task("clean", done => {
del(buildDir).then(() => done()).catch(err => done(err));
});
gulp.task("build-content-script-js", () => {
return browserify(`./${sourceDir}/content-script/index.js`)
.transform(babelify)
.bundle()
.pipe(source("content-script.js")) // Convert from Browserify stream to vinyl stream.
.pipe(buffer()) // Convert from streaming mode to buffered mode.
.pipe(uglify({ mangle: false }))
.pipe(gulp.dest(buildDir));
});
gulp.task("build-content-script-css", () => {
return gulp
.src(`${sourceDir}/content-script/index.less`)
.pipe(less())
.pipe(minifyCSS())
.pipe(rename("content-script.css"))
.pipe(gulp.dest(buildDir));
});
gulp.task("build-icon", () => {
return gulp
.src(`${sourceDir}/icon.png`)
.pipe(imageResize({ width: 128, height: 128, crop: true }))
.pipe(rename("icon128.png"))
.pipe(gulp.dest(buildDir))
.pipe(imageResize({ width: 48, height: 48, crop: true }))
.pipe(rename("icon48.png"))
.pipe(gulp.dest(buildDir))
.pipe(imageResize({ width: 16, height: 16, crop: true }))
.pipe(rename("icon16.png"))
.pipe(gulp.dest(buildDir));
});
gulp.task("build-manifest", () => {
return gulp
.src(`${sourceDir}/manifest.json`)
.pipe(jsonminify())
.pipe(gulp.dest(buildDir));
});
gulp.task("build", ["clean"], done => {
runSequence(["build-content-script-js", "build-content-script-css", "build-icon", "build-manifest"], done);
});
gulp.task("watch", ["build"], () => {
return watch(`${sourceDir}/**/*`, () => { runSequence("build") });
});
gulp.task("default", ["build"]);