-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
85 lines (76 loc) · 2.06 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
const gulp = require("gulp");
const del = require("del");
const concat = require("gulp-concat");
const terser = require("gulp-terser");
const postcss = require("gulp-postcss");
const image = require("gulp-image");
const babel = require("gulp-babel");
const sass = require("gulp-sass");
sass.compiler = require("node-sass");
const nunjucksRender = require("gulp-nunjucks-render");
const cssnano = require("cssnano");
const uncss = require("postcss-uncss");
const autoprefixer = require("autoprefixer");
const sourceFolder = "source";
const outputFolder = "dest";
gulp.task("clean", function () {
return del(`${outputFolder}/**`, { force: true });
});
gulp.task("build:html", function () {
return gulp
.src(`${sourceFolder}/pages/**/*.+(html|nunjucks|njk)`)
.pipe(
nunjucksRender({
path: [`${sourceFolder}/templates`],
})
)
.pipe(gulp.dest(outputFolder));
});
gulp.task("build:assets", function () {
return gulp
.src([`${sourceFolder}/static/assets/**`])
.pipe(image())
.pipe(gulp.dest(`${outputFolder}/assets`));
});
gulp.task("build:js", function () {
return gulp
.src([
`${sourceFolder}/static/js/vendor/*.js`,
`${sourceFolder}/static/js/main.js`,
])
.pipe(
babel({
presets: ["@babel/env"],
})
)
.pipe(concat("js/bundle.js"))
.pipe(terser())
.pipe(gulp.dest(outputFolder));
});
gulp.task("build:css", function () {
return gulp
.src(`${sourceFolder}/static/css/**.+(css|scss)`)
.pipe(sass().on("error", sass.logError))
.pipe(concat("css/styles.css"))
.pipe(
postcss([
uncss({
html: [`${outputFolder}/*.html`],
timeout: 100,
}),
autoprefixer,
cssnano,
])
)
.pipe(gulp.dest(outputFolder));
});
gulp.task("deploy", function () {
// write your script here to deploy app to your server
});
gulp.task(
"build",
gulp.series(["clean", "build:html", "build:js", "build:assets", "build:css"])
);
gulp.task("watch", function () {
return gulp.watch(`${sourceFolder}/**`, gulp.series(["build"]));
});