-
Notifications
You must be signed in to change notification settings - Fork 1
/
next.config.js
34 lines (28 loc) · 961 Bytes
/
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
const path = require('path')
const dir = require('node-dir')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { ANALYZE } = process.env
module.exports = {
webpack: function (config) {
if (ANALYZE) {
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerPort: 8888,
openAnalyzer: true
}))
}
return config
},
exportPathMap: function () {
const pagesDir = 'pages'
const pages = dir.files(pagesDir, { sync: true })
.filter(page => !page.includes('_'))
.map(page => '/' + path.relative(pagesDir, page))
.map(page => path.posix.format(path.parse(page)))
.map(page => page.replace('/index.js', ''))
.map(page => page.replace('.js', ''))
.map(page => page || '/')
.reduce((acc, page) => Object.assign(acc, { [page]: { page } }), {})
return Object.assign({ '/404.html': { page: '/_error' } }, pages)
}
}