This repository was archived by the owner on Dec 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
65 lines (57 loc) · 1.74 KB
/
gulpfile.js
File metadata and controls
65 lines (57 loc) · 1.74 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
const { src, dest, parallel, series, watch } = require('gulp');
const pug = require('gulp-pug');
const concat = require('gulp-concat');
const clean = require('gulp-clean');
const inject = require('gulp-inject');
const posthtml = require('gulp-posthtml');
const esbuild = require('gulp-esbuild');
const postcss = require('gulp-postcss');
const connect = require('gulp-connect');
const pugOptions = require('./pug.config');
const esbuildWatch = esbuild.createGulpEsbuild();
const TARGET_DIR = 'build';
const INTERMEDIATE_FILES = [`${TARGET_DIR}/**/*.js`, `${TARGET_DIR}/**/*.css`];
function build({ production, watchMode }) {
const esbuildTask = watchMode ? esbuildWatch : esbuild;
return series(
parallel(
() =>
src('src/**/*.css')
.pipe(postcss())
.pipe(concat('styles.css'))
.pipe(dest(TARGET_DIR)),
() =>
src('src/**/*.entry.js')
.pipe(
esbuildTask({
bundle: true,
minify: production,
}),
)
.pipe(concat('index.js'))
.pipe(dest(TARGET_DIR)),
),
() =>
src('src/index.pug')
.pipe(pug(pugOptions))
.pipe(
inject(src(INTERMEDIATE_FILES, { read: false }), {
removeTags: true,
relative: true,
}),
)
.pipe(posthtml())
.pipe(dest(TARGET_DIR)),
);
}
module.exports.build = series(
() => src(TARGET_DIR, { allowEmpty: true }).pipe(clean()),
build({ production: true, watchMode: false }),
);
module.exports.dev = series(
build({ production: false, watchMode: false }),
parallel(
() => watch('./src/**', build({ production: false, watchMode: false })),
() => connect.server({ root: TARGET_DIR }),
),
);