-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
39 lines (31 loc) · 1.36 KB
/
webpack.config.babel.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
const { merge } = require('webpack-merge');
const buildValidations = require('./webpack/build-validations');
const commonConfig = require('./webpack/webpack.common');
// We can include Webpack plugins, through addons, that do
// not need to run every time we are developing.
// We will see an example when we set up 'Bundle Analyzer'
const addons = (/* string | string[] */ addonsArg) => {
// Normalize array of addons (flatten)
const addons = [...[addonsArg]]
.filter(Boolean); // If addons is undefined, filter it out
return addons.map((addonName) => require(`./webpack/addons/webpack.${addonName}.js`))
}
// 'env' will contain the environment variable from 'scripts'
// section in 'package.json'.
// console.log(env); => { env: 'dev' }
module.exports = (env) => {
// We use 'buildValidations' to check for the 'env' flag
if (!env) {
throw new Error(buildValidations.ERR_NO_ENV_FLAG)
}
// Select which Webpack configuration to use; development
// or production
// console.log(env.env); => dev
const envConfig = require(`./webpack/webpack.${env.env}.js`)
// 'webpack-merge' will combine our shared configurations, the
// environment specific configurations and any addons we are
// including
const mergedConfig = merge(commonConfig, envConfig, ...addons(env.addons))
// Then return the final configuration for Webpack
return mergedConfig
}