forked from expo/expo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
52 lines (49 loc) · 1.72 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
const withCSS = require('@zeit/next-css');
const { copySync, removeSync } = require('fs-extra');
const { join } = require('path');
const semver = require('semver');
const { version } = require('./package.json');
// copy versions/v(latest version) to versions/latest
// (Next.js only half-handles symlinks)
const vLatest = join('pages', 'versions', `v${version}/`);
const latest = join('pages', 'versions', 'latest/');
removeSync(latest);
copySync(vLatest, latest);
module.exports = withCSS({
// 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')],
});
config.node = {
fs: 'empty',
};
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 {
// hide versions greater than the package.json version number
const versionMatch = pathname.match(/\/v(\d\d\.\d\.\d)\//);
if (versionMatch && versionMatch[1] && semver.gt(versionMatch[1], version)) {
return {};
}
return { [pathname]: page };
}
})
);
},
});