-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathesbuild.js
63 lines (54 loc) · 1.6 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
const { malinaPlugin } = require('malinajs/malina-esbuild');
const { build } = require('esbuild');
const { derver } = require('derver');
const {fetchDeps} = require('./fetch-deps');
const {generateExamples} = require('./examples-generator');
const dev = process.argv.includes('--dev');
(async ()=>{
// Generating examples
generateExamples(!dev);
// Fetch all Malina's version
await fetchDeps();
// Make bundle for application
const bundleApp = await build({
entryPoints: ['src/main.js'],
outfile: 'public/bundle.js',
minify: !dev,
incremental: dev,
sourcemap: dev,
bundle: true,
plugins: [
malinaPlugin({
hideLabel: !dev
})
]
});
// Make bundle for bundle worker
const bundleWorker = await build({
entryPoints: ['src/bundler/worker.js'],
outfile: 'public/bundler_worker.js',
minify: !dev,
sourcemap: dev,
incremental: dev,
bundle: true
});
// Serve in development mode
if(dev){
derver({
dir: 'public',
watch: ['public','src'],
onwatch: async (lr,item)=>{
if(item === 'src'){
lr.prevent();
try{
await bundleApp.rebuild();
await bundleWorker.rebuild();
}catch(err){
console.log(err.message);
lr.error(err.toString(),'Build error');
}
}
}
})
}
})();