-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
executable file
·40 lines (32 loc) · 970 Bytes
/
build.js
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
const path = require("path");
const webpack = require("webpack");
/**
* Creates application build using different config files
*/
(function () {
const configFile = process.argv[2];
if (!configFile) {
console.log(`Please specify a config file. Example: \n \
npm run build -- async \n \
npm run build -- initial \n \
npm run build -- maxSize \n \
npm run build -- false \n`);
return;
}
return new Promise((resolve, reject) => {
const webpackConfig = require(path.resolve(process.cwd(), `webpack.${configFile}.config.js`));
if (!webpackConfig) {
return reject(new Error("Webpack config not found."));
}
webpack(webpackConfig, (err, stats) => {
if (err) {
return reject(err);
}
console.info(stats.toString(webpackConfig.stats));
if (stats.hasErrors()) {
return reject(new Error("Webpack compilation errors"));
}
return resolve();
});
});
})();