forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
49 lines (44 loc) · 1.55 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
const {dest, series, src} = require("gulp");
const del = require("del");
const inline = require("gulp-inline-source");
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const htmlmin = require("gulp-html-minifier-terser");
// will be building from a clone of the public directory
// if not for this, the global stylesheets would get prefixed which are used in development
function copy() {
return src("./public/**/*")
.pipe(dest("./temp"));
}
// autoprefix select stylesheets and overwrite in place
function autoprefix() {
return src(["./temp/build/bundle.css", "./temp/css/global.css"])
.pipe(postcss([
autoprefixer({overrideBrowserslist: ["last 4 version"]})
]))
.pipe(dest(file => file.base));
}
// conditionally inline dev.js if bundling a demo page based on env var set in package.json
// inline the rest of the asset for a monolithic html file
function bundle() {
const d = process.env.NODE_ENV === "demo" ? "./" : "./extension/Userscripts Extension";
return src("./temp/index.html")
.pipe(inline({
attribute: false,
compress: false,
ignore: []
}))
.pipe(htmlmin({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true
}))
.pipe(dest(d));
}
// remove the temp folder
function clean() {
return del("./temp");
}
exports.demo = series(copy, autoprefix, bundle, clean);
exports.build = series(copy, autoprefix, bundle, clean);