Make exportTrailingSlash
stable (#7746)
This commit is contained in:
parent
e36d7b3226
commit
b2a9670ca4
8 changed files with 22 additions and 18 deletions
|
@ -24,6 +24,7 @@ const defaultConfig: { [key: string]: any } = {
|
||||||
amp: {
|
amp: {
|
||||||
canonicalBase: '',
|
canonicalBase: '',
|
||||||
},
|
},
|
||||||
|
exportTrailingSlash: false,
|
||||||
experimental: {
|
experimental: {
|
||||||
cpus: Math.max(
|
cpus: Math.max(
|
||||||
1,
|
1,
|
||||||
|
@ -31,7 +32,6 @@ const defaultConfig: { [key: string]: any } = {
|
||||||
(os.cpus() || { length: 1 }).length) - 1
|
(os.cpus() || { length: 1 }).length) - 1
|
||||||
),
|
),
|
||||||
ampBindInitData: false,
|
ampBindInitData: false,
|
||||||
exportTrailingSlash: false,
|
|
||||||
terserLoader: false,
|
terserLoader: false,
|
||||||
profiling: false,
|
profiling: false,
|
||||||
flyingShuttle: false,
|
flyingShuttle: false,
|
||||||
|
|
|
@ -817,6 +817,7 @@ Router.events.on('routeChangeError', (err, url) => {
|
||||||
|
|
||||||
> **Note**: Using router events in `getInitialProps` is discouraged as it may result in unexpected behavior.<br/>
|
> **Note**: Using router events in `getInitialProps` is discouraged as it may result in unexpected behavior.<br/>
|
||||||
> Router events should be registered when a component mounts (`useEffect` or `componentDidMount`/`componentWillUnmount`) or imperatively when an event happens.
|
> Router events should be registered when a component mounts (`useEffect` or `componentDidMount`/`componentWillUnmount`) or imperatively when an event happens.
|
||||||
|
>
|
||||||
> ```js
|
> ```js
|
||||||
> useEffect(() => {
|
> useEffect(() => {
|
||||||
> const handleRouteChange = url => {
|
> const handleRouteChange = url => {
|
||||||
|
@ -2211,7 +2212,7 @@ Any AMP errors will cause `next export` to exit with status code `1` because the
|
||||||
|
|
||||||
### TypeScript Support
|
### TypeScript Support
|
||||||
|
|
||||||
AMP currently doesn't have built-in types for Typescript, but it's in their roadmap ([#13791](https://github.com/ampproject/amphtml/issues/13791)). As a workaround you can manually add the types to `amp.d.ts` like [here](https://stackoverflow.com/a/50601125).
|
AMP currently doesn't have built-in types for TypeScript, but it's in their roadmap ([#13791](https://github.com/ampproject/amphtml/issues/13791)). As a workaround you can manually add the types to `amp.d.ts` like [here](https://stackoverflow.com/a/50601125).
|
||||||
|
|
||||||
## Static HTML export
|
## Static HTML export
|
||||||
|
|
||||||
|
@ -2265,7 +2266,20 @@ module.exports = {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note that if the path ends with a directory, it will be exported as `/dir-name/index.html`, but if it ends with an extension, it will be exported as the specified filename, e.g. `/readme.md` above. If you use a file extension other than `.html`, you may need to set the `Content-Type` header to `text/html` when serving this content.
|
The pages will be exported as html files, i.e. `/about` will become `/about.html`.
|
||||||
|
|
||||||
|
It is possible to configure Next.js to export pages as `index.html` files and require trailing slashes, i.e. `/about` becomes `/about/index.html` and is routable via `/about/`.
|
||||||
|
This was the default behavior prior to Next.js 9.
|
||||||
|
You can use the following `next.config.js` to switch back to this behavior:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// next.config.js
|
||||||
|
module.exports = {
|
||||||
|
exportTrailingSlash: true,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note**: If the export path is a filename (e.g. `/readme.md`) and is different than `.html`, you may need to set the `Content-Type` header to `text/html` when serving this content.
|
||||||
|
|
||||||
The second argument is an `object` with:
|
The second argument is an `object` with:
|
||||||
|
|
||||||
|
|
|
@ -406,10 +406,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
|
||||||
const exportConfig = {
|
const exportConfig = {
|
||||||
...config,
|
...config,
|
||||||
exportPathMap: (defaultMap: any) => defaultMap,
|
exportPathMap: (defaultMap: any) => defaultMap,
|
||||||
experimental: {
|
|
||||||
...config.experimental,
|
|
||||||
exportTrailingSlash: false,
|
exportTrailingSlash: false,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
await exportApp(dir, exportOptions, exportConfig)
|
await exportApp(dir, exportOptions, exportConfig)
|
||||||
const toMove = await recursiveReadDir(exportOptions.outdir, /.*\.html$/)
|
const toMove = await recursiveReadDir(exportOptions.outdir, /.*\.html$/)
|
||||||
|
|
|
@ -441,7 +441,7 @@ export default async function getBaseWebpackConfig(
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
'process.env.__NEXT_EXPORT_TRAILING_SLASH': JSON.stringify(
|
'process.env.__NEXT_EXPORT_TRAILING_SLASH': JSON.stringify(
|
||||||
config.experimental.exportTrailingSlash
|
config.exportTrailingSlash
|
||||||
),
|
),
|
||||||
...(isServer
|
...(isServer
|
||||||
? { 'typeof window': JSON.stringify('undefined') }
|
? { 'typeof window': JSON.stringify('undefined') }
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default async function (dir, options, configuration) {
|
||||||
const concurrency = options.concurrency || 10
|
const concurrency = options.concurrency || 10
|
||||||
const threads = options.threads || Math.max(cpus().length - 1, 1)
|
const threads = options.threads || Math.max(cpus().length - 1, 1)
|
||||||
const distDir = join(dir, nextConfig.distDir)
|
const distDir = join(dir, nextConfig.distDir)
|
||||||
const subFolders = nextConfig.experimental.exportTrailingSlash
|
const subFolders = nextConfig.exportTrailingSlash
|
||||||
|
|
||||||
if (!options.buildExport && nextConfig.target !== 'server') {
|
if (!options.buildExport && nextConfig.target !== 'server') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
experimental: {
|
|
||||||
exportTrailingSlash: false
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ const access = promisify(fs.access)
|
||||||
const appDir = join(__dirname, '../')
|
const appDir = join(__dirname, '../')
|
||||||
const outdir = join(appDir, 'out')
|
const outdir = join(appDir, 'out')
|
||||||
|
|
||||||
describe('Export experimental.exportTrailingSlash set to false', () => {
|
describe('Export config#exportTrailingSlash set to false', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await nextBuild(appDir)
|
await nextBuild(appDir)
|
||||||
await nextExport(appDir, { outdir })
|
await nextExport(appDir, { outdir })
|
||||||
|
|
|
@ -9,9 +9,7 @@ module.exports = phase => {
|
||||||
serverRuntimeConfig: {
|
serverRuntimeConfig: {
|
||||||
bar: 'bar'
|
bar: 'bar'
|
||||||
},
|
},
|
||||||
experimental: {
|
exportTrailingSlash: true,
|
||||||
exportTrailingSlash: true
|
|
||||||
},
|
|
||||||
exportPathMap: function () {
|
exportPathMap: function () {
|
||||||
return {
|
return {
|
||||||
'/': { page: '/' },
|
'/': { page: '/' },
|
||||||
|
|
Loading…
Reference in a new issue