-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.js
More file actions
41 lines (37 loc) · 1.26 KB
/
Copy pathwebpack.js
File metadata and controls
41 lines (37 loc) · 1.26 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
const webpack = require('webpack');
const path = require('path');
const mode = process.argv[2];
let config = require(path.resolve(process.argv[3] || 'webpack.config'));
if (typeof config === 'function') config = config(mode);
config = Array.isArray(config) ? config : [config];
for (const item of config) item.mode = mode === 'watch' ? 'development' : mode;
let lastHash = null;
function compilerCallback(err, stats) {
if (mode !== 'watch' || err) compiler.purgeInputFileSystem();
if (err) {
lastHash = null;
console.error(err.stack || err);
if (err.details) console.error(err.details);
process.exit(1);
}
if (stats.hash !== lastHash) {
lastHash = stats.hash;
const statsString = stats.toString({
colors: require('supports-color'),
context: config[0].context,
cached: false,
cachedAssets: false,
exclude: ['node_modules'],
timings: true
});
if (statsString) process.stdout.write(statsString + '\n');
}
if (mode !== 'watch' && stats.hasErrors()) {
process.exitCode = 2;
console.error('FULL ERROR', stats.stats[0].compilation.errors[0]);
}
}
const compiler = webpack(config);
if (mode === 'watch')
compiler.watch(config[0].watchOptions || {}, compilerCallback);
else compiler.run(compilerCallback);