1const { join } = require('path'); 2const { copySync, removeSync } = require('fs-extra'); 3 4// copy versions/v(latest version) to versions/latest 5// (Next.js only half-handles symlinks) 6const vLatest = join('pages', 'versions', `v${require('./package.json').version}/`); 7const latest = join('pages', 'versions', 'latest/'); 8removeSync(latest); 9copySync(vLatest, latest); 10 11module.exports = { 12 // Rather than use `@zeit/next-mdx`, we replicate it 13 pageExtensions: ['js', 'jsx', 'md', 'mdx'], 14 webpack: (config, options) => { 15 config.module.rules.push({ 16 test: /.mdx?$/, // load both .md and .mdx files 17 use: [ 18 options.defaultLoaders.babel, 19 '@mdx-js/loader', 20 join(__dirname, './common/md-loader'), 21 ], 22 }); 23 return config; 24 }, 25 async exportPathMap(defaultPathMap, { dev, dir, outDir }) { 26 if (dev) { 27 return defaultPathMap; 28 } 29 copySync(join(dir, 'robots.txt'), join(outDir, 'robots.txt')); 30 return Object.assign( 31 ...Object.entries(defaultPathMap).map(([pathname, page]) => { 32 if (pathname.match(/\/v[1-9][^\/]*$/)) { 33 // ends in "/v<version>" 34 pathname += '/index.html'; // TODO: find out why we need to do this 35 } 36 37 if (pathname.match(/unversioned/)) { 38 return {}; 39 } else { 40 return { [pathname]: page }; 41 } 42 }) 43 ); 44 }, 45}; 46