44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const commonConfig = require("./build-utils/webpack.common");
|
|
const webpackMerge = require("webpack-merge");
|
|
|
|
const defaultEnv = { env: "prod" };
|
|
|
|
/**
|
|
*
|
|
* @param {string|Array} addonsArg
|
|
* @return {unknown[]}
|
|
*/
|
|
const addons = addonsArg => {
|
|
// Normalize array of addons (flatten).
|
|
let addons = [].concat
|
|
.apply([], [addonsArg])
|
|
// If addons is undefined, filter it out.
|
|
.filter(Boolean);
|
|
|
|
return addons.map(addonName =>
|
|
require(`./build-utils/addons/webpack.${addonName}.js`)
|
|
);
|
|
};
|
|
|
|
// Export a function returning config instead of a static config.
|
|
// The purpose is to allow use of the environment.
|
|
module.exports = (env = defaultEnv) => {
|
|
if (!env || !env.env) {
|
|
throw new Error(
|
|
"You must pass an -env.env flag into your build for webpack to work"
|
|
);
|
|
}
|
|
|
|
console.log("Env: ", env);
|
|
const envConfig = require(`./build-utils/webpack.${env.env}`);
|
|
|
|
// The rightmost overwrites (merges into) its left sibling.
|
|
const mergedConfig = webpackMerge(
|
|
commonConfig,
|
|
envConfig,
|
|
...addons(env.addons)
|
|
);
|
|
|
|
console.log(mergedConfig);
|
|
return mergedConfig;
|
|
};
|