-
Notifications
You must be signed in to change notification settings - Fork 3
/
esbuild.js
176 lines (163 loc) · 5.42 KB
/
esbuild.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* global process */
// ESBUILD PROJECT DEPENDENCIES
import * as esbuild from "esbuild";
//Local ESBUILD PLUGINS
import QgdsPluginHandlebarPartialBuilder from "./.esbuild/plugins/qgds-plugin-handlebar-partial-builder.js";
import QgdsPluginHandlebarHelpersRollup from "./.esbuild/plugins/qgds-plugin-handlebar-helpers-rollup.js";
import QgdsPluginSassGlobBuilder from "./.esbuild/plugins/qgds-plugin-sass-glob-builder.js";
import QgdsPluginGlobalJsRollup from "./.esbuild/plugins/qgds-plugin-global-js-rollup.js";
import QGDSrawLoader from "./.esbuild/plugins/qgds-plugin-raw-loader.js";
import QDGScleanFolders from "./.esbuild/plugins/qgds-plugin-clean-output-folders.js";
import QDGSbuildLog from "./.esbuild/plugins/qgds-plugin-build-log.js";
import QDGScopy from "./.esbuild/plugins/qgds-plugin-copy-assets.js";
import { esBuildHandlebarsEmbedSvgPlugin } from './.esbuild/plugins/handlebarsEmbedSvgPlugin.js'
//Open source ESBUILD PLUGINS
import { sassPlugin } from "esbuild-sass-plugin";
import handlebarsPlugin from "esbuild-plugin-handlebars";
//Command line arguments are available via argv object
import minimist from "minimist";
const argv = minimist(process.argv.slice(2));
// https://esbuild.github.io/getting-started/#build-scripts
const buildConfig = {
bundle: true,
minify: true,
sourcemap: true,
target: ["es6"],
logLevel: "info",
outdir: "./dist/",
external: ["fs", "path", "handlebars", "../img/*"],
entryPoints: [
//This needs to be dynamically generated based off the tokens theme's
{
in: "./src/js/main.js",
out: "./assets/js/main.min",
},
{
in: "./src/css/main-campaign-neon.scss",
out: "./assets/css/main-campaign-neon.min",
},
{
in: "./src/css/main-campaign-neon-invert.scss",
out: "./assets/css/main-campaign-neon-invert.min",
},
{
in: "./src/css/main-qld-corporate.scss",
out: "./assets/css/main-qld-corporate.min",
},
{
in: "./src/css/main-qld-corporate-invert.scss",
out: "./assets/css/main-qld-corporate-invert.min",
},
{
in: "./src/css/main.scss",
out: "./assets/css/main.min",
},
{
in: "./src/css/main-invert.scss",
out: "./assets/css/main-invert.min",
},
{
in: "./src/css/main-qld-high-contrast.scss",
out: "./assets/css/main-qld-high-contrast.min",
},
{
in: "./src/css/main-qld-high-contrast-invert.scss",
out: "./assets/css/main-qld-high-contrast-invert.min",
},
{
in: "./src/css/main-qld-maroon.scss",
out: "./assets/css/main-qld-maroon.min",
},
{
in: "./src/css/main-qld-maroon-invert.scss",
out: "./assets/css/main-qld-maroon-invert.min",
}
],
loader: {
".html": "text",
".hbs": "text",
".js": "jsx",
".jpg": "file",
".png": "file",
".gif": "file",
".svg": "file",
".eot": "file",
".woff": "file",
".ttf": "file",
},
plugins: [
QgdsPluginHandlebarPartialBuilder(),
QgdsPluginHandlebarHelpersRollup(),
esBuildHandlebarsEmbedSvgPlugin(),
QgdsPluginSassGlobBuilder(),
QgdsPluginGlobalJsRollup(),
QDGScopy(),
QGDSrawLoader(),
handlebarsPlugin(),
sassPlugin(),
QDGSbuildLog(),
],
};
const buildDevConfig = {
...buildConfig,
entryPoints: buildConfig.entryPoints.map(entry => ({
...entry,
out: entry.out.replace('.min', '') // Replaces '.min' with an empty string
})),
// plugins: buildConfig.plugins.filter((plugin) => {
// // Assuming QDGScleanFolders is a named function:
// return plugin.name !== "qgds-clean-output-folders";
// }),
minify: false,
sourcemap: true
};
const buildNodeConfig = {
loader: buildConfig.loader,
bundle: true,
minify: false,
sourcemap: true,
minifyIdentifiers: false,
logLevel: buildConfig.logLevel,
outdir: buildConfig.outdir,
external: buildConfig.external,
platform: "node",
target: ["node20"],
format: 'esm',
entryPoints: [
{
in: "./src/helpers/handlebars.init.cjs",
out: "./assets/helpers/handlebars.init.min",
},
],
plugins: [
QgdsPluginHandlebarPartialBuilder(),
QgdsPluginHandlebarHelpersRollup(),
esBuildHandlebarsEmbedSvgPlugin(),
QDGScopy(),
QGDSrawLoader(),
handlebarsPlugin(),
QDGSbuildLog(),
],
}
async function StartBuild() {
let ctx = await esbuild.context(buildConfig);
let ctxDev = await esbuild.context(buildDevConfig);
let ctxNode = await esbuild.context(buildNodeConfig);
//clean
await esbuild.build({plugins: [QDGScleanFolders()]});
if (argv.watch === true) {
// "npm run watch"
await Promise.all([ctx.watch(), ctxDev.watch(), ctxNode.watch(), new Promise(resolve => { /* never resolve */
})]);
} else if (argv.clean === true) {
//done
} else {
await Promise.all([ctxNode.rebuild(), ctx.rebuild(), ctxDev.rebuild()]);
//await Promise.all([ctxNode.rebuild()]);
}
await ctx.dispose();
await ctxDev.dispose();
await ctxNode.dispose();
}
//Initate the project build...
StartBuild();