fchat-rising/webpack.js

36 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

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']});
if(statsString) process.stdout.write(statsString + '\n');
}
2024-07-07 00:30:34 +00:00
if(mode !== 'watch' && stats.hasErrors()) {
process.exitCode = 2;
console.error('FULL ERROR', stats.stats[0].compilation.errors[0]);
}
}
2020-06-20 18:43:34 +00:00
console.log(config);
const compiler = webpack(config);
if(mode === 'watch') compiler.watch({}, compilerCallback);
2020-06-20 18:43:34 +00:00
else compiler.run(compilerCallback);