-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathesbuild.js
118 lines (104 loc) · 2.8 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
/* global process */
// ESBUILD PROJECT DEPENDENCIES
import * as esbuild from "esbuild";
//Local ESBUILD PLUGINS
import QGDSupdateHandlebarsPartialsPlugin from "./.esbuild/plugins/qgds-plugin-handlebar-partial-builder.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 { versionPlugin } from "./.esbuild/plugins/qgds-plugin-version.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", "bootstrap", "../img/*"],
entryPoints: [
{
in: "./src/js/qld.bootstrap.js",
out: "./assets/js/qld.bootstrap.min",
},
{
in: "./src/css/main.scss",
out: "./assets/css/qld.bootstrap",
},
{
in: "./src/js/handlebars.helpers.js",
out: "./assets/js/handlebars.helpers.bundle",
},
{
in: "./src/js/handlebars.init.js",
out: "./assets/js/handlebars.init.min",
},
],
loader: {
".html": "text",
".hbs": "text",
".js": "jsx",
".jpg": "file",
".png": "file",
},
plugins: [
QGDSupdateHandlebarsPartialsPlugin(),
QDGScopy(),
QGDSrawLoader(),
versionPlugin(),
QDGScleanFolders(),
handlebarsPlugin(),
sassPlugin(),
QDGSbuildLog(),
],
};
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/js/handlebars.init.cjs",
out: "./assets/node/handlebars.init.min",
},
],
plugins: [
QGDSupdateHandlebarsPartialsPlugin(),
QDGScopy(),
QGDSrawLoader(),
versionPlugin(),
handlebarsPlugin(),
],
}
async function StartBuild() {
let ctx = await esbuild.context(buildConfig);
if (argv.watch === true) {
// "npm run watch"
await ctx.watch();
} else {
// "npm run build" or "node build.js"
await ctx.rebuild();
await ctx.dispose();
}
//node js module
let ctxNode = await esbuild.context(buildNodeConfig);
await ctxNode.rebuild();
await ctxNode.dispose();
}
//Initate the project build...
StartBuild();