forked from bbc/simorgh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
razzle.config.js
114 lines (105 loc) · 4.19 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
114
const BrotliPlugin = require('brotli-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const OfflinePlugin = require('offline-plugin');
module.exports = {
modify: (config, { target, dev }) => {
const appConfig = config;
if (!dev) {
/*
This is a hack to disable linting on the production build.
Linting is the first object in the rules away and this removes it.
A prod build will fail if the API changes so it is fairly safe.
*/
appConfig.module.rules.shift();
// Setup bundle analyser
if (target === 'web') {
// setup bundle splitting
appConfig.output.filename = 'static/js/[name].[hash:8].js';
appConfig.optimization = {
splitChunks: {
chunks: 'initial',
automaticNameDelimiter: '-',
minSize: 184320, // 180kb
maxSize: 245760, // 240kb
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
},
},
},
};
// Setup service worker and offline support
appConfig.plugins.push(
new OfflinePlugin({
AppCache: false, // because it's deprecated
appShell: '/news/articles/',
autoUpdate: 1000 * 60 * 60 * 6, // 6 hours
// externals means files not generated by webpack
// an alternative would be html-webpack-plugin
caches: 'all',
externals: [
'https://gel.files.bbci.co.uk/r2.302/BBCReithSans_W_Rg.woff2',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSans_W_Rg.woff',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSerif_W_Md.woff2',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSerif_W_Md.woff',
/* Unused fonts
- When adding fonts, be sure to add them to the globalStyles object here:
https://github.com/BBC-News/simorgh/blob/latest/src/app/lib/globalStyles.js#L5
'https://gel.files.bbci.co.uk/r2.302/BBCReithSans_W_Lt.woff2',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSans_W_Lt.woff',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSerif_W_Lt.woff2',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSerif_W_Lt.woff',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSerif_W_Rg.woff2',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSerif_W_Rg.woff',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSerif_W_Bd.woff2',
'https://gel.files.bbci.co.uk/r2.302/BBCReithSerif_W_Bd.woff',
End of unused fonts */
],
ServiceWorker: {
events: true,
minify: true,
},
updateStrategy: 'changed',
}),
new BrotliPlugin({
asset: '[path].br[query]',
test: /\.js$/,
threshold: 10240,
minRatio: 0.8,
}),
new CompressionPlugin({
algorithm: 'gzip',
filename: '[path].gz[query]',
test: /\.js$/,
threshold: 10240,
minRatio: 0.8,
}),
);
}
// Setup bundle analyser
if (target === 'web' && !process.env.CI) {
// const defined here because it's a dev dep (breaks production build if at top of file)
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); // eslint-disable-line import/no-extraneous-dependencies, global-require
appConfig.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
defaultSizes: 'gzip',
generateStatsFile: true,
openAnalyzer: false,
reportFilename: '../../reports/webpackBundleReport.html',
statsFilename: '../../reports/webpackBundleReport.json',
}),
);
}
}
// This is to override bundle performance test
if (process.env.CI) {
appConfig.performance = {
maxAssetSize: 245760, // 240kb - individual bundles
maxEntrypointSize: 491520, // 480kb - total bundles
};
}
return appConfig;
},
};