mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 15:15:19 +00:00
Enforce prod mode, return a Promise so it can be used programmatically
This commit is contained in:
11
lib/build.js
11
lib/build.js
@@ -1,3 +1,5 @@
|
|||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const mkdirp = require('mkdirp');
|
const mkdirp = require('mkdirp');
|
||||||
@@ -14,15 +16,16 @@ module.exports = () => {
|
|||||||
// create main.js and server-routes.js
|
// create main.js and server-routes.js
|
||||||
create_app();
|
create_app();
|
||||||
|
|
||||||
|
return new Promise((fulfil, reject) => {
|
||||||
function handleErrors(err, stats) {
|
function handleErrors(err, stats) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err ? err.details || err.stack || err.message || err : 'Unknown error');
|
reject(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stats.hasErrors()) {
|
if (stats.hasErrors()) {
|
||||||
console.log(stats.toString({ colors: true }));
|
console.error(stats.toString({ colors: true }));
|
||||||
process.exit(1);
|
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, ' '));
|
fs.writeFileSync(path.join(dest, 'stats.server.json'), JSON.stringify(serverInfo, null, ' '));
|
||||||
|
|
||||||
generate_asset_cache(clientInfo, serverInfo);
|
generate_asset_cache(clientInfo, serverInfo);
|
||||||
|
fulfil();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user