forked from chaskiq/chaskiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.mjs
82 lines (76 loc) · 1.89 KB
/
esbuild.config.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
import esbuild from 'esbuild';
import babel from './babel-esbuild.mjs';
const watch = process.argv.includes('--watch')
const minify = process.argv.includes('--minify')
const metafile = process.argv.includes('--metafile')
console.log("WATCH: ", watch)
console.log("MINIFY: ", minify)
console.log("METAFILE: ", metafile)
let ctx = await esbuild.context({
logLevel: 'info',
target: 'es2020',
sourcemap: watch ? 'inline' : false,
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV}"`,
'global': 'window',
'process.env.NODE_DEBUG': '""',
'define': 'undefined'
},
platform: 'browser',
inject: ['./esbuild/process-shim.js'],
entryPoints: [
"app/javascript/application.js",
"app/javascript/embed.js",
"app/javascript/article.js",
"app/javascript/docs.js",
"app/javascript/locales.js",
"app/javascript/twilio_phone_package.js"
],
bundle: true,
loader: {
'.png': 'file',
'.js': 'jsx',
},
metafile,
minify,
publicPath: "/assets",
assetNames: '[name]-[hash].digested',
//splitting: true,
//chunkNames: '[name]-[hash].digested',
//format: 'esm',
banner: {
js: `
${
watch ?
`
(
() => {
const sse = new EventSource("http://localhost:3001/esbuild");
sse.addEventListener("change", (e) => {
console.log("Esbuild message:", e.data);
location.reload();
});
}
)();
`
: ''
}
`
},
outdir: 'app/assets/builds',
plugins: [
babel({
filter: /\.([^cpj].*|c([^s].*)?|cs([^s].*)?|css.+|p([^n].*)?|pn([^g].*)?|png.+|j([^s].*)?|js([^o].*)?|jso([^n].*)?|json.+)$/,
})
]
})
if( watch ){
await ctx.watch()
let { host, port } = await ctx.serve({
port: 3001,
servedir: 'app/assets/builds',
})
} else {
ctx.rebuild()
ctx.dispose()
}