forked from bbc/simorgh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
109 lines (104 loc) · 3.03 KB
/
webpack.config.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* eslint-disable import/no-dynamic-require, global-require */
const merge = require('webpack-merge');
const fs = require('fs');
const path = require('path');
const appDirectory = fs.realpathSync(process.cwd());
const resolvePath = relativePath => path.resolve(appDirectory, relativePath);
// `shell` parameter populated via CLI, e.g. --env.platform=web
module.exports = (shell = {}) => {
const IS_PROD = process.env.NODE_ENV === 'production';
const IS_CI = process.env.CI;
const START_DEV_SERVER = !IS_PROD;
const CONFIG_FILE = shell.config;
const stats = IS_PROD
? {}
: {
// reduce verbosity of console output
assets: false,
children: false,
chunks: false,
hash: false,
modules: false,
publicPath: false,
timings: false,
version: false,
warnings: true,
colors: true, // color the console output in terminal
entrypoints: false,
};
const baseConfig = {
mode: IS_PROD ? 'production' : 'development',
devtool: IS_PROD ? 'source-map' : 'cheap-eval-source-map',
resolve: { extensions: ['.js', '.jsx'] }, // resolves `import '../Foo'` to `../Foo/index.jsx`
devServer: {
stats,
},
stats,
node: {
// tell Webpack to provide a polyfill for this functionality.
__filename: true,
__dirname: true,
},
module: {
rules: [
// tell Webpack to use the .babelrc to know how to transform JS/JSX to ES2015 JS
{
test: /\.(js|jsx|mjs)$/,
include: [resolvePath('src')],
use: [
{
loader: 'babel-loader',
options: {
babelrc: true,
cacheDirectory: true,
presets: [],
},
},
],
},
IS_PROD
? {
test: /\.(js|jsx|mjs)$/,
include: [resolvePath('node_modules/@bbc')],
use: [
{
loader: 'babel-loader',
options: {
presets: [],
plugins: [
[
'transform-react-remove-prop-types',
{
mode: 'remove',
removeImport: true,
},
],
],
},
},
],
}
: {},
],
},
// Bundle sizes are monitored by `./scripts/bundleSize.sh`
performance: {
hints: false,
},
};
const mergeIntoBaseConfig = app => {
const specialisedConfig = require(`./webpack.config.${app}.js`)({
resolvePath,
IS_PROD,
IS_CI,
START_DEV_SERVER,
});
return merge(baseConfig, specialisedConfig);
};
// if we've passed env.config, just compile that one file
if (CONFIG_FILE) {
return mergeIntoBaseConfig(CONFIG_FILE);
}
// else compile both (we've run `webpack` on its own)
return ['client', 'server'].map(mergeIntoBaseConfig);
};