forked from dancespiele/yew_styles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wasm-builder.js
41 lines (31 loc) · 1.19 KB
/
wasm-builder.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
const { execSync } = require('child_process');
const Bundler = require('parcel-bundler');
const Path = require('path');
const chokidar = require('chokidar');
const dotenv = require('dotenv');
dotenv.config();
const entryFiles = Path.join(__dirname, 'index.html');
const buildType = process.argv[2];
const options = {
outDir: './dist',
outFile: 'index.html',
publicUrl: '/',
watch: true,
minify: buildType === 'production',
};
(async () => {
const bundler = new Bundler(entryFiles, options);
chokidar.watch(['./crate/src', './crate/Cargo.toml', './crate/yew_styles/src', './crate/yew_styles/Cargo.toml']).on('change', async (event, path) => {
console.log(`there are new changes in '${path}'. Start to rebuild rustwasm sources`);
bundler.bundle();
bundler.hmr.broadcast({
type: 'reload'
});
});
bundler.on('buildStart', () => {
const prevtBuildFile = Path.join(__dirname, './wasm_pack_cmd');
console.log(`running: ${prevtBuildFile}`);
execSync(`${prevtBuildFile} ${buildType === 'production' ? '' : '--dev'}`, {stdio: 'inherit'});
});
await bundler.serve(process.env.SERVER_ADDRESS || 1234);
})();