-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
45 lines (39 loc) · 1.29 KB
/
build.js
File metadata and controls
45 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const path = require('path');
const webpack = require('webpack');
const webpackConfigBuilder = require('./webpack.config.js');
const webpackBuild = (config) =>
new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err || stats.hasErrors()) {
reject(stats);
} else {
resolve(stats);
}
});
});
const { build: buildMaintenance } = require('./src/js/maintenance/build.js');
const build = async () => {
const webpackConfig = webpackConfigBuilder('production');
// Build project with Webpack
let webpackStats;
try {
webpackStats = await webpackBuild(webpackConfig);
} catch (error) {
webpackStats = error;
}
if (webpackStats.hasErrors()) {
process.stderr.write(`Webpack build failed:\n${webpackStats.toString({ colors: true })}\n\n`);
throw new Error('Webpack build failed');
} else {
process.stdout.write(`Webpack build completed successfully:\n${webpackStats.toString({ colors: true })}\n\n`);
}
// Build maintenance.html (depends on dist/404.js from webpack)
await buildMaintenance({
distPath: path.resolve(__dirname, webpackConfig.output.path),
srcPath: path.resolve(__dirname, 'src'),
});
};
build().catch((error) => {
process.stderr.write(`Build failed: ${error.message}\n`);
process.exit(1);
});