-
Notifications
You must be signed in to change notification settings - Fork 16
/
next.config.js
71 lines (59 loc) · 1.78 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
69
70
71
const {join} = require('path')
const nextRuntimeDotenv = require('next-runtime-dotenv')
// The following modules will be pushed to the commons.js bundle
const commonModules = [
'/node_modules/fbjs/',
'/node_modules/lodash-es/',
'/node_modules/marked/',
'/node_modules/next/',
'/node_modules/scheduler/',
'/node_modules/webpack/',
'/components/hoc/',
'/lib/session.js',
'/pages/_error.js'
]
const withConfig = nextRuntimeDotenv({
public: [
'PUBLIC_URL',
'DATAGOUV_API_URL',
'DATAGOUV_API_KEY',
'PUBLICATION_BASE_URL',
'GEODATA_API_URL',
'TRANSCODER_URL',
'PIWIK_URL',
'PIWIK_SITE_ID'
]
})
module.exports = withConfig({
webpack(config, {dev, isServer}) {
const {ContextReplacementPlugin} = require('webpack')
config.plugins.push(
new ContextReplacementPlugin(/moment[/\\]locale$/, /fr/)
)
if (!dev && !isServer) {
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer')
config.optimization.splitChunks.cacheGroups.shared = {
name: 'commons',
test: m => m.resource && commonModules.some(c =>
m.resource.startsWith(join(__dirname, c))
)
}
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
reportFilename: join(__dirname, 'reports/bundles.html'),
defaultSizes: 'gzip'
}))
config.resolve.alias = {
...config.resolve.alias,
// Replace lodash with lodash-es on client side.
// This reduces the bundles sizes greatly and allows for webpack
// scope hoisting in other dependencies.
// Both lodash and lodash-es should be installed, as lodash-es
// will not work server-side.
lodash: 'lodash-es'
}
}
return config
}
})