-
Notifications
You must be signed in to change notification settings - Fork 4
/
esbuild.config.mjs
86 lines (73 loc) · 2.22 KB
/
esbuild.config.mjs
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
86
/*
On recommendation from @valentine195.
Config based on @jdanielmourao's Sanctum theme esbuild setup.
(https://github.com/jdanielmourao/obsidian-sanctum)
Further based on https://github.com/damiankorcz/Prism-Theme/blob/main/esbuild.config.mjs
Updated to Esbuild 17 by @Sigrunixia
Usage:
Dev build
$ node esbuild.config.mjs
Prod build
$ node esbuild.config.mjs production
Dev build for one system only (pf2e or bnb):
$ node esbuild.config.mjs <system>
Dev build for one system only (pf2e or bnb), output to outfile:
$ node esbuild.config.mjs <system> <outfile>
*/
import * as esbuild from "esbuild";
import { config } from "dotenv";
import { sassPlugin } from "esbuild-sass-plugin";
import time from 'esbuild-plugin-time';
config();
const dir = "./";
const isProd = process.argv[2] === "production";
// The systems that will be built. By default and in prod, build all. The values here correspond to the
// keys of the systemConfig object below.
const systems = (isProd || !process.argv[2]) ? ["pf2e", "bnb"] : [process.argv[2]];
// The output file. Ignored in production.
const devFile = process.argv[3];
// The specific system config set here will overwrite the default config entries
// set below.
const systemConfig = {
// PF2E
pf2e: {
// Entry point should be where everything is imported into.
entryPoints: ["pf2e-index.scss"],
// Path for final file
outfile: isProd ? `${dir}/Basic-Pathfinder-2e-Layout.css` : (devFile || `${dir}/Basic-Pathfinder-2e-Layout-DEV.css`),
},
// BNB Bestiary
bnb: {
minify: true,
// Entry point should be where everything is imported into.
entryPoints: ["bnb-index.scss"],
// Path for final file
outfile: isProd ? `${dir}/BnB-Layout.css` : (devFile || `${dir}/BnB-Layout-DEV.css`),
}
}
async function build(systemConfig) {
const config = {
logLevel: "info",
plugins: [
sassPlugin({
cache: true,
charset: false,
alertColor: true,
alertAscii: true,
}),
time()
],
...systemConfig
};
if (isProd) {
await esbuild.build(config);
} else {
const context = await esbuild.context(config)
await context.rebuild();
await context.watch();
}
}
// Build the files
for (var system of systems) {
build(systemConfig[system]).catch(() => process.exit(1))
}