Enforce prod mode, return a Promise so it can be used programmatically

This commit is contained in:
Rich Harris
2018-01-14 13:45:01 -05:00
committed by GitHub
parent d6dda371ca
commit 6a4dc1901c

View File

@@ -1,3 +1,5 @@
process.env.NODE_ENV = 'production';
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
@@ -14,15 +16,16 @@ module.exports = () => {
// create main.js and server-routes.js
create_app();
return new Promise((fulfil, reject) => {
function handleErrors(err, stats) {
if (err) {
console.error(err ? err.details || err.stack || err.message || err : 'Unknown error');
reject(err);
process.exit(1);
}
if (stats.hasErrors()) {
console.log(stats.toString({ colors: true }));
process.exit(1);
console.error(stats.toString({ colors: true }));
reject(new Error(`Encountered errors while building app`));
}
}
@@ -37,6 +40,8 @@ module.exports = () => {
fs.writeFileSync(path.join(dest, 'stats.server.json'), JSON.stringify(serverInfo, null, ' '));
generate_asset_cache(clientInfo, serverInfo);
fulfil();
});
});
});
};