forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
47 lines (40 loc) · 1.2 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
'use strict'
const envFlag = require('node-env-flag')
const webpack = require('webpack')
const shouldAnalyze = envFlag(process.env.ANALYZE)
const assetPrefix = process.env.NEXT_ASSET_PREFIX
module.exports = {
webpack: config => {
config.plugins.push(
new webpack.EnvironmentPlugin({ BASE_URL: null, LONG_CACHE: null })
)
if (shouldAnalyze) {
// We don't include webpack-bundle-analyzer in devDependencies, so load
// lazily.
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerPort: 8888,
openAnalyzer: true,
})
)
}
config.module.loaders = (config.module.loaders || []).concat({
test: /\.json$/,
loader: 'json-loader',
})
if (assetPrefix) {
config.output.publicPath = `${assetPrefix}/${config.output.publicPath}`
}
return config
},
exportPathMap: () => ({
'/': { page: '/' },
}),
}
// Avoid setting an `undefined` value. This causes
// `TypeError: Cannot read property 'replace' of undefined` at build time.
if (assetPrefix) {
module.exports.assetPrefix = assetPrefix
}