-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.mjs
83 lines (75 loc) · 2.31 KB
/
bundle.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
import * as esbuild from 'esbuild'
import * as fs from 'fs'
// import _esOptions from './bundle.config.mjs'
const args = process.argv.slice(2)
const buildType = args[0]
// Load custom config if exists (bundle.config.json), otherwise set some defaults
export const _esOptions =
fs.existsSync("./bundle.config.json") ?
await JSON.parse(fs.readFileSync('./bundle.config.json', "utf8")) :
{
outdir: ".",
entryPoints: [
{ in: "./src/css/main.css", out: "./dist/css/bundle" },
{ in: "./src/js/main.js", out: "./dist/js/bundle" },
],
bundle: true,
write: true,
minify: true,
sourcemap: true,
logLevel: 'info',
external: [ // Ignore public paths (e.g. static images, fonts, ..)
'./public/*', '../public/*',
'./static/*', '../static/*'
],
"supported": {
"nesting": false
}
// loader: { '.jpg': 'file', '.gif': 'file', '.png': 'file' },
// packages: 'external', // External dependency loading during runtime
// target: ['node10.4'], // Specify target (node version) if needed
}
export const _esBuilder = async function(_esOptions) {
if(_esOptions.length > 0) {
_esOptions.forEach(async options => {
await esbuild.build(options)
});
} else {
await esbuild.build(_esOptions)
}
console.log('Build seems complete.')
}
export const _esWatcher = async function(_esOptions) {
if(_esOptions.length > 0) {
_esOptions.forEach(async options => {
const ctx = await esbuild.context(options)
await ctx.watch()
});
} else {
const ctx = await esbuild.context(_esOptions)
await ctx.watch()
}
console.log('Watching...')
}
export default {
_esOptions,
_esBuilder,
_esWatcher
}
if(buildType) {
switch (buildType) {
case "options":
console.log("_esOptions: ")
console.log(_esOptions)
break;
case "build":
_esBuilder(_esOptions)
break;
case "watch":
_esWatcher(_esOptions)
break;
default:
console.log("Please specify one of the following arguments as string: \"build\", \"watch\" or \"options\"")
break;
}
}