-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnext.config.js
79 lines (69 loc) · 1.9 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
72
73
74
75
76
77
78
79
const path = require('path')
const rehypePrism = require('@mapbox/rehype-prism')
const rehypeReadme = require('./lib/rehype-readme')
const nextMDX = require('@zeit/next-mdx')
// only enable rehypeReadme for this file
// because the github relative path replacement
// might break things in other markdowns
const withGitHubMDX = nextMDX({
extension: path.join(__dirname, 'components', 'docs', 'docs.mdx'),
options: {
hastPlugins: [
rehypePrism,
[
rehypeReadme,
{
repo: 'rehooks/template',
branch: 'master',
level: 4
}
]
]
}
})
const withMDX = nextMDX({
extension: /\/(pages)\/(.+)\.mdx?$/,
options: {
hastPlugins: [rehypePrism]
}
})
const webpack = require('webpack')
var config = {
pageExtensions: ['jsx', 'js', 'mdx'],
webpack: (config, { dev, isServer }) => {
config.plugins = config.plugins || []
config.plugins.push(
new webpack.ContextReplacementPlugin(
/highlight\.js[\/\\]lib[\/\\]languages$/,
new RegExp(`^./(${['javascript', 'json', 'xml'].join('|')})$`)
)
)
if (isServer && !dev) {
const originalEntry = config.entry
config.entry = async () => {
const entries = { ...(await originalEntry()) }
return entries
}
}
return config
}
}
if (process.env.BUNDLE_ANALYZE) {
const withBundleAnalyzer = require('@zeit/next-bundle-analyzer')
config = withBundleAnalyzer({
analyzeServer: ['server', 'both'].includes(process.env.BUNDLE_ANALYZE),
analyzeBrowser: ['browser', 'both'].includes(process.env.BUNDLE_ANALYZE),
bundleAnalyzerConfig: {
server: {
analyzerMode: 'static',
reportFilename: '../../bundles/server.html'
},
browser: {
analyzerMode: 'static',
reportFilename: '../bundles/client.html'
}
},
...config
})
}
module.exports = withGitHubMDX(withMDX(config))