-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
97 lines (86 loc) · 2.58 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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: 'zeit/next.js',
branch: 'master',
level: 4
}
]
]
}
});
const withMDX = nextMDX({
extension: /\/(pages|blog)\/(.+)\.mdx?$/,
options: {
hastPlugins: [rehypePrism]
}
});
const { mapping: showcaseMapping } = require('./showcase-manifest');
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()) };
// This script imports components from the Next app, so it's transpiled to `.next/server/scripts/build-rss.js`
entries['./scripts/build-rss.js'] = './scripts/build-rss.js';
return entries;
};
}
return config;
},
exportPathMap(defaultPathMap, { dev, dir, outDir }) {
for (const route of Object.keys(showcaseMapping)) {
defaultPathMap[`/showcase/${route}`] = {
page: '/showcase',
query: { item: route, from: 'url' }
};
}
if (!dev) {
const generateRSS = require('./.next/server/scripts/build-rss.js')
.default;
generateRSS(outDir);
}
return defaultPathMap;
}
};
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));