This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnext.config.js
68 lines (63 loc) · 1.74 KB
/
next.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
require('@babel/polyfill');
const withCss = require('@zeit/next-css');
const withSass = require('@zeit/next-sass');
const withBundleAnalyzer = require('@zeit/next-bundle-analyzer');
const isProd =
process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging';
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const LodashReplacement = new LodashModuleReplacementPlugin({
paths: true,
collections: true,
currying: true,
});
const webpackConfig = {
webpack: (config) => {
const originalEntry = config.entry;
/* eslint-disable no-param-reassign */
config.entry = async () => {
const entries = await originalEntry();
if (
entries['main.js'] &&
!entries['main.js'].includes('./app/utils/polyfills.js')
) {
entries['main.js'].unshift('./app/utils/polyfills.js');
}
return entries;
};
config.plugins = config.plugins || [];
config.plugins.push(LodashReplacement);
/* eslint-enable no-param-reassign */
return config;
},
};
if (process.env.ANALYZE_BUNDLE) {
module.exports = withBundleAnalyzer({
...withSass(
withCss({
...webpackConfig,
generateBuildId: async () => process.env.BUILD_ID,
}),
),
analyzeServer: ['server', 'both'].includes(process.env.ANALYZE_BUNDLE),
analyzeBrowser: ['browser', 'both'].includes(process.env.ANALYZE_BUNDLE),
bundleAnalyzerConfig: {
server: {
analyzerMode: 'static',
reportFilename: '../bundles/server.html',
},
browser: {
analyzerMode: 'static',
reportFilename: '../bundles/client.html',
},
},
});
} else if (isProd) {
module.exports = withSass(
withCss({
...webpackConfig,
generateBuildId: async () => process.env.BUILD_ID,
}),
);
} else {
module.exports = withSass(withCss(webpackConfig));
}