-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
44 lines (42 loc) · 1.34 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
const { join } = require('path');
const { copySync, removeSync } = require('fs-extra');
// copy versions/v(latest version) to versions/latest
// (Next.js only half-handles symlinks)
const vLatest = join('pages', 'versions', `v${require('./package.json').version}/`);
const latest = join('pages', 'versions', 'latest/');
removeSync(latest);
copySync(vLatest, latest);
module.exports = {
// Rather than use `@zeit/next-mdx`, we replicate it
pageExtensions: ['js', 'jsx', 'md', 'mdx'],
webpack: (config, options) => {
config.module.rules.push({
test: /.mdx?$/, // load both .md and .mdx files
use: [
options.defaultLoaders.babel,
'@mdx-js/loader',
join(__dirname, './common/md-loader'),
],
});
return config;
},
async exportPathMap(defaultPathMap, { dev, dir, outDir }) {
if (dev) {
return defaultPathMap;
}
copySync(join(dir, 'robots.txt'), join(outDir, 'robots.txt'));
return Object.assign(
...Object.entries(defaultPathMap).map(([pathname, page]) => {
if (pathname.match(/\/v[1-9][^\/]*$/)) {
// ends in "/v<version>"
pathname += '/index.html'; // TODO: find out why we need to do this
}
if (pathname.match(/unversioned/)) {
return {};
} else {
return { [pathname]: page };
}
})
);
},
};