2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 01:14:03 +00:00
books/webpack/build.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

const webpack = require('webpack');
2018-10-21 09:06:53 +00:00
const { getConfig, getElectronMainConfig } = require('./config');
module.exports = function build(mode) {
2018-10-21 09:06:53 +00:00
const rendererConfig = getConfig();
const mainConfig = getElectronMainConfig();
process.env.NODE_ENV = 'production';
if (mode === 'electron') {
2018-10-21 09:06:53 +00:00
pack(rendererConfig)
.then(result => {
console.log(result);
}).catch(err => {
console.log(`\n Failed to build renderer process`);
console.error(`\n${err}\n`);
process.exit(1)
2018-10-21 09:06:53 +00:00
});
pack(mainConfig)
.then(result => {
console.log(result);
}).catch(err => {
console.log(`\n Failed to build main process`);
console.error(`\n${err}\n`);
process.exit(1)
});
}
}
function pack(config) {
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err) reject(err.stack || err)
else if (stats.hasErrors()) {
let err = ''
stats
.toString({
chunks: false,
colors: true
})
.split(/\r?\n/)
.forEach(line => {
err += ` ${line}\n`
});
reject(err);
} else {
resolve(stats.toString({
chunks: false,
colors: true
}));
}
});
});
}