-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev.js
53 lines (47 loc) · 1.23 KB
/
dev.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
const spawn = require('cross-spawn');
const path = require('path');
const webpack = require('webpack');
const webpackConfigClient = require('./webpack.config.client');
const webpackConfigServer = require('./webpack.config.server');
const compiler = webpack([
{
...webpackConfigClient,
mode: 'development',
devtool: 'source-map',
output: {
...webpackConfigClient.output,
filename:'[name].js'
},
},
{
...webpackConfigServer,
mode: 'development',
devtool: 'source-map',
},
]);
let node;
compiler.hooks.watchRun.tap('Dev', (compiler) => {
console.log(`Compiling ${compiler.name} ...`);
if(compiler.name === 'server' && node) {
node.kill();
node = undefined;
}
});
compiler.watch({},(err,stats) => {
if(err) {
console.error(err);
process.exit(1)
}
console.log(stats?.toString('minimal'))
const compiledSuccessfully = !stats?.hasErrors()
if (compiledSuccessfully && !node) {
console.log('Starting Node.js ...')
node = spawn(
'node',
['--inspect', path.join(__dirname, 'public','server.js')],
{
stdio: 'inherit',
}
)
}
});