-
Notifications
You must be signed in to change notification settings - Fork 3
/
config-overrides.js
73 lines (69 loc) · 2.06 KB
/
config-overrides.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
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const configuration = {
jsOutput: {
filename: 'static/js/[name].js',
chunkFilename: 'static/js/[name].chunk.js',
},
cssOutput: {
filename: 'static/css/[name].css',
chunkFilename: 'static/css/[name].chunk.css',
},
};
function rewireProduction(config, type) {
return {
...config,
devtool: false,
output: {
...config.output,
filename: configuration.jsOutput.filename,
chunkFilename: configuration.jsOutput.chunkFilename,
},
plugins: [
...config.plugins.map((item, index) => {
if (!(item.options && item.options.filename && item.options.filename.includes('.css'))) {
return item;
}
return new MiniCssExtractPlugin({
filename: configuration.cssOutput.filename,
chunkFilename: configuration.cssOutput.chunkFilename,
});
}),
],
optimization: {
runtimeChunk: 'single',
splitChunks: {
maxInitialRequests: Infinity,
minSize: 40000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
chunks(chunk) {
return chunk.name === 'main';
},
name(module, chunks, cacheGroupKey) {
const moduleFileName = module
.identifier()
.split('/')
.reduceRight(item => item);
const allChunksNames = chunks.map(item => item.name).join('~');
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
return type === 'function' ? `${cacheGroupKey}-${allChunksNames}-${moduleFileName}` : packageName.replace('@', '');
},
},
},
},
},
};
}
function rewireDevelopment(config) {
return config;
}
module.exports = function override(config, env) {
const isDev = env === 'development';
if (isDev) {
return rewireDevelopment(config);
}
return rewireProduction(config);
};