-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
43 lines (40 loc) · 1.13 KB
/
bundle.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
import ESBuild from 'esbuild'
import { sassPlugin } from 'esbuild-sass-plugin'
// Is this a development run & should we serve public?
const _DEV_ = process.argv.some(env => env === 'dev')
const _SERVER_ = process.argv.some(env => env === 'server')
// Configuration for ESBuild
const esBuildConfig = {
entryPoints: ['scss/sassStyle.scss'],
bundle: true,
color: true,
logLevel: 'info',
sourcemap: _DEV_,
minify: !_DEV_,
target: 'es6',
outdir: 'public',
plugins: [sassPlugin()]
}
try {
// In development mode, we want to watch the files and serve them
if (_DEV_) {
const ctx = await ESBuild.context(esBuildConfig)
await ctx.watch()
if (_SERVER_) {
// Dynamically serve changes
await ctx.serve({
port: 3000,
servedir: 'public'
})
} else {
// Watch and rebuild, but don't serve files
await ESBuild.build(esBuildConfig)
}
} else {
// In production mode, we just want to build the files once (no watch)
await ESBuild.build(esBuildConfig)
}
} catch (err) {
console.error('An error occurred while building and/or serving the project.')
console.error(err)
}