-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·44 lines (36 loc) · 1.21 KB
/
index.js
File metadata and controls
executable file
·44 lines (36 loc) · 1.21 KB
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
#!/usr/bin/env node
const path = require('path');
const childProcess = require('child_process');
const webpack = require('webpack');
const argv = require('yargs').argv;
const options = {
config: argv.config || 'webpack.config',
chunk: argv.chunk || 'main'
};
const webpackConfiguration = require(path.join(process.cwd(), options.config));
const compiler = webpack(webpackConfiguration);
let outputProcess;
compiler.plugin('done', function(stats) {
if (stats.hasErrors()) {
console.log(stats.compilation.errors.join('\n'));
return;
}
if (!outputProcess) {
const outputDirectory = stats.compilation.compiler.outputPath;
const outputFile = stats.toJson().assetsByChunkName[options.chunk];
if (!outputFile) {
throw `Chunk '${options.chunk}' has no assets`;
}
const outputPath = path.join(outputDirectory, outputFile);
outputProcess = childProcess.fork(outputPath);
} else {
// TODO: Validate that webpack is in idle mode before sending signal
// does not actually kill the process - `hot/signal` reloads on receiving SIGUSR2 signals
outputProcess.kill('SIGUSR2');
}
});
compiler.watch(options.watchOptions, function(error, stats) {
if (error) {
throw error;
}
});