electron/build/webpack/run-compiler.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
2019-06-02 20:03:03 +00:00
const configPath = process.argv[2];
const outPath = path.resolve(process.argv[3]);
const config = require(configPath);
2019-06-02 20:03:03 +00:00
config.output = {
path: path.dirname(outPath),
filename: path.basename(outPath)
};
2019-06-02 20:03:03 +00:00
const { wrapInitWithProfilingTimeout, wrapInitWithTryCatch, ...webpackConfig } = config;
webpack(webpackConfig, (err, stats) => {
2019-06-02 20:03:03 +00:00
if (err) {
console.error(err);
process.exit(1);
2019-06-02 20:03:03 +00:00
} else if (stats.hasErrors()) {
console.error(stats.toString('normal'));
process.exit(1);
2019-06-02 20:03:03 +00:00
} else {
let contents = fs.readFileSync(outPath, 'utf8');
if (wrapInitWithTryCatch) {
contents = `try {
${contents}
} catch (err) {
console.error('Electron ${webpackConfig.output.filename} script failed to run');
console.error(err);
}`;
}
if (wrapInitWithProfilingTimeout) {
contents = `function ___electron_webpack_init__() {
${contents}
};
if ((globalThis.process || binding.process).argv.includes("--profile-electron-init")) {
setTimeout(___electron_webpack_init__, 0);
} else {
___electron_webpack_init__();
}`;
}
fs.writeFileSync(outPath, contents);
process.exit(0);
2019-06-02 20:03:03 +00:00
}
});