-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
67 lines (59 loc) · 1.3 KB
/
build.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
import * as esbuild from "esbuild";
import postcss from "postcss";
import autoprefixer from "autoprefixer";
import { sassPlugin } from "esbuild-sass-plugin";
import { purgeCSSPlugin } from "@fullhuman/postcss-purgecss";
const args = process.argv.slice(2);
const watch = args.includes("--watch");
const production = args.includes("--production");
// To enable PurgeCSS, set content folders here and uncomment purgeCssPlugin
// below.
const purgeCss = purgeCSSPlugin({
content: ["./**/*.html"],
});
const postCssPlugins = [
autoprefixer,
// To enable PurgeCSS, set content folders above and uncomment line below.
// purgeCss
];
const plugins = [
sassPlugin({
async transform(source, resolveDir) {
const { css } = await postcss(postCssPlugins).process(source, {
from: undefined,
});
return css;
},
}),
];
// Define esbuild options
let opts = {
entryPoints: ["src/js/main.js"],
bundle: true,
logLevel: "info",
target: "es2017",
outdir: "build/css",
plugins: plugins,
};
if (production) {
opts = {
...opts,
minify: true,
};
}
if (watch) {
opts = {
...opts,
sourcemap: "inline",
};
esbuild
.context(opts)
.then((ctx) => {
ctx.watch();
})
.catch((_error) => {
process.exit(1);
});
} else {
esbuild.build(opts);
}