提交 be4026f4 编写于 作者: P Pierre de la Martinière 提交者: Tim Neutkens

Make next export respect experimental.exportTrailingSlash (#6752)

* Add --no-subfolders argument to next export

* Use experimental.exportTrailingSlash instead of a cli flag

* Add experimental.exportTrailingSlash documentation

* Add tests for export with experimental.exportTrailingSlash

* Remove docs

* Remove comment
上级 87f60f56
......@@ -24,6 +24,7 @@ export default async function (dir, options, configuration) {
const concurrency = options.concurrency || 10
const threads = options.threads || Math.max(cpus().length - 1, 1)
const distDir = join(dir, nextConfig.distDir)
const subFolders = nextConfig.experimental.exportTrailingSlash
if (nextConfig.target !== 'server') throw new Error('Cannot export when target is not server. https://err.sh/zeit/next.js/next-export-serverless')
......@@ -139,7 +140,8 @@ export default async function (dir, options, configuration) {
outDir,
renderOpts,
serverRuntimeConfig,
concurrency
concurrency,
subFolders
})
worker.on('message', ({ type, payload }) => {
if (type === 'progress' && progress) {
......
......@@ -26,7 +26,8 @@ process.on(
outDir,
renderOpts,
serverRuntimeConfig,
concurrency
concurrency,
subFolders
}) => {
const sema = new Sema(concurrency, { capacity: exportPaths.length })
try {
......@@ -47,6 +48,9 @@ process.on(
})
let htmlFilename = `${path}${sep}index.html`
if (!subFolders) htmlFilename = `${path}.html`
const pageExt = extname(page)
const pathExt = extname(path)
// Make sure page isn't a folder with a dot in the name e.g. `v1.2`
......
module.exports = {
experimental: {
exportTrailingSlash: false
}
}
export default () => (
<p>I am an about page</p>
)
export default () => (
<p>I am a home page</p>
)
export default () => (
<p>I am a list of posts</p>
)
export default () => (
<p>I am a single post</p>
)
/* eslint-env jest */
/* global jasmine */
import fs from 'fs'
import { join } from 'path'
import cheerio from 'cheerio'
import { promisify } from 'util'
import {
nextBuild,
nextExport
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
const readFile = promisify(fs.readFile)
const access = promisify(fs.access)
const appDir = join(__dirname, '../')
const outdir = join(appDir, 'out')
describe('Export experimental.exportTrailingSlash set to false', () => {
beforeAll(async () => {
await nextBuild(appDir)
await nextExport(appDir, { outdir })
})
it('should export pages as [filename].html instead of [filename]/index.html', async () => {
expect.assertions(6)
await expect(access(join(outdir, 'index.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'about.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'posts.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'posts', 'single.html'))).resolves.toBe(undefined)
const html = await readFile(join(outdir, 'index.html'))
const $ = cheerio.load(html)
expect($('p').text()).toBe('I am a home page')
const htmlSingle = await readFile(join(outdir, 'posts', 'single.html'))
const $single = cheerio.load(htmlSingle)
expect($single('p').text()).toBe('I am a single post')
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册