-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.js
64 lines (60 loc) · 1.69 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
52
53
54
55
56
57
58
59
60
61
62
63
64
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 Dotenv = require('dotenv-webpack');
const compiler = webpack([
{
...webpackConfigClient,
mode: 'development',
devtool: 'source-map',
output: {
...webpackConfigClient.output,
filename: '[name].js',
},
plugins: [
...webpackConfigClient.plugins.filter(plugin => !(plugin instanceof Dotenv)),
new Dotenv({
path: './.development.env'
}),
]
},
{
...webpackConfigServer,
mode: 'development',
devtool: 'source-map',
plugins: [
...webpackConfigServer.plugins.filter(plugin => !(plugin instanceof Dotenv)),
new Dotenv({
path: './.development.env'
}),
]
},
]);
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, 'dist/server.js')],
{
stdio: 'inherit',
}
)
}
});