forked from trento-project/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
54 lines (48 loc) · 1.5 KB
/
build.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
/* eslint-disable no-undef */
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const alias = require('esbuild-plugin-path-alias');
const esbuild = require('esbuild');
const resolvePath = (p) => path.resolve(__dirname, p);
const watching = Boolean(process.env.ESBUILD_WATCH);
const buildConfig = {
entryPoints: ['js/app.js', 'js/trento.jsx'],
outdir: resolvePath('../priv/static/assets'),
bundle: true,
minify: !process.env.ESBUILD_WATCH,
sourcemap: process.env.ESBUILD_WATCH ? 'inline' : false,
loader: {
'.png': 'dataurl',
'.svg': 'dataurl',
},
plugins: [
alias({
phoenix: resolvePath('../deps/phoenix/priv/static/phoenix.mjs'),
phoenix_html: resolvePath(
'../deps/phoenix_html/priv/static/phoenix_html.js'
),
phoenix_live_view: resolvePath(
'../deps/phoenix_live_view/priv/static/phoenix_live_view.esm.js'
),
'@common': resolvePath('./js/common'),
'@hooks': resolvePath('./js/hooks'),
'@lib': resolvePath('./js/lib'),
'@pages': resolvePath('./js/pages'),
'@state': resolvePath('./js/state'),
'@static': resolvePath('./static'),
}),
],
};
const build = async () => {
if (watching) {
const context = await esbuild.context(buildConfig);
console.log('=> JS bundle was built!');
console.log('=> Watching...');
context.watch();
} else {
await esbuild.build(buildConfig);
console.log('=> JS bundle was built!');
}
};
build();