-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
67 lines (62 loc) · 1.79 KB
/
build.js
File metadata and controls
67 lines (62 loc) · 1.79 KB
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
const esbuild = require('esbuild')
const { htmlPlugin } = require('@craftamap/esbuild-plugin-html')
const outputFolder = process.env.NODE_ENV === 'production' ? 'docs' : 'dist/'
const main = async () => {
const pluginsList = [htmlPlugin({
files: [{
entryPoints: [
'src/index.js',
],
filename: 'index.html',
title: 'Visualizer',
serve: process.env.NODE_ENV !== 'production',
define: {
env: process.env.NODE_ENV ? process.env.NODE_ENV : 'development',
},
htmlTemplate: 'src/index.html.template',
}],
})]
const buildOptions = {
entryPoints: ['src/index.js'],
bundle: true,
metafile: true,
minify: true,
sourcemap: true,
target: ['chrome58', 'firefox57', 'safari11', 'edge16'],
outdir: outputFolder,
assetNames: '[name]',
plugins: pluginsList,
logLevel: 'info',
}
if( process.env.NODE_ENV === 'production' ) {
// build mode
await esbuild.build(buildOptions)
} else {
// Start dev server
const livery = (await import('livery')).default
const { fileWatcher } = livery(outputFolder, {
delay: 250,
httpPort: 3000,
livePort: 35729,
spa: false,
watch: outputFolder + '*.*',
})
// watch and rebuild files live
await esbuild.build(Object.assign({}, buildOptions, {
watch: {
onRebuild(error, result) {
if( error ) {
console.error('watch build failed', error)
} else {
console.log('watch build succeeded')
// Livery uses Chokidar and on Windows, Chokidar is crappy.
// Force a reload when ESBuild rebuilds.
// This is fine to do regardless of OS since it's debounced.
fileWatcher.emit('all')
}
},
},
}))
}
}
main()