-
Notifications
You must be signed in to change notification settings - Fork 4
/
esbuild.js
69 lines (59 loc) · 1.5 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
import {build, analyzeMetafile, serve} from 'esbuild'
import {buildHTML} from './bin/rebuild-html.js'
import {copyFiles} from './bin/copy-to-dist.js'
const outputDir = 'dist'
const entry_points = {
viewer: 'src/views/viewer.js',
singleview: 'src/views/singleview.js',
twinview: 'src/views/twinview.js',
style: 'src/index.css'
}
if (process.env.NODE_ENV === 'production') {
// Production build
build({
entryPoints: entry_points,
outdir: outputDir,
bundle: true,
minify: true,
metafile: true,
splitting: true,
entryNames: '[name]-[hash]',
format: 'esm',
loader: {
'.ttf': 'file',
'.svg': 'file'
},
banner: {
js: `// Skråfoto v${ process.env.npm_package_version }`,
css: `/* Skråfoto v${ process.env.npm_package_version } */`,
}
})
.then(async (result) => {
await buildHTML(entry_points, result.metafile.outputs, outputDir)
await copyFiles()
analyzeMetafile(result.metafile).then((analysis) => {
//console.log(analysis)
console.log('Build finished 👍')
})
})
.catch(() => process.exit(1))
} else {
// Development mode watches for file changes and rebuilds
serve({
servedir: 'public',
}, {
entryPoints: entry_points,
loader: {
'.ttf': 'file',
'.svg': 'file'
},
outdir: 'public',
bundle: true,
splitting: true,
format: 'esm'
}).then(server => {
console.log(server)
// Call "stop" on the web server to stop serving
// server.stop()
})
}