-
Notifications
You must be signed in to change notification settings - Fork 0
/
razzle.config.js
113 lines (107 loc) · 3.25 KB
/
razzle.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
110
111
112
113
const nodeExternals = require('webpack-node-externals');
const fs = require('fs');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const BrotliGzipPlugin = require('brotli-gzip-webpack-plugin');
const path = require('path');
const findRuleIndex = (config, ruleLabel) =>
config.module.rules.findIndex(
rule =>
rule.use &&
rule.use.find(use => use.loader && use.loader.includes(ruleLabel))
);
module.exports = {
modify: (config, { target, dev }, webpack) => {
config.resolve.extensions.push('.ts', '.tsx');
config.resolve.alias['styled-components'] = require.resolve(
'styled-components'
);
config.resolve.modules.push(path.resolve(__dirname, 'node_modules'));
const babelRuleIndex = findRuleIndex(config, 'babel-loader');
config.module.rules[babelRuleIndex] = Object.assign(
config.module.rules[babelRuleIndex],
{
test: /\.(js|ts|tsx|css)$/
}
);
config.externals =
target === 'node'
? [
nodeExternals({
whitelist: [
dev ? 'webpack/hot/poll?300' : null,
/\.(woff2|svg|png|jpg|jpeg|gif|ico|webp)$/,
/^@culture-trip\//
].filter(Boolean)
})
]
: [];
if (target === 'web') {
config.output.filename = dev
? 'static/js/[name].js'
: 'static/js/[name].[hash:8].js';
config.output.jsonpFunction = 'webpackV4Jsonp';
config.externals.push({
react: 'React',
'react-dom': 'ReactDOM',
'styled-components': 'styled'
});
config.optimization = {
...config.optimization,
// create a single runtime bundle for all chunks, improves cacheability
// https://webpack.js.org/guides/caching/#extracting-boilerplate
runtimeChunk: 'single',
// keep module ids more stable between builds
// https://webpack.js.org/guides/caching/#module-identifiers
moduleIds: 'hashed',
splitChunks: {
cacheGroups: {
vendor: {
test(mod) {
if (!mod.context || !mod.context.includes('node_modules')) {
return false;
}
return !mod.context.includes('@culture-trip');
},
name: 'vendor',
chunks: 'all'
}
}
}
};
if (!dev) {
config.output.publicPath = '/bookable/';
config.plugins.push(
new BrotliGzipPlugin({
asset: '[path].br[query]',
algorithm: 'brotli',
test: /\.(js)$/,
threshold: 0,
minRatio: 0.8,
quality: 11
})
);
config.plugins.push(
new BrotliGzipPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js)$/,
threshold: 0,
minRatio: 0.8
})
);
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
defaultSizes: 'gzip',
reportFilename: './bundle-analyzer/client.html'
})
);
config.performance = {
hints: false
};
}
}
return config;
}
};