mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
feat(generator): allow excluding exported pages using export:page
hook (#7455)
This commit is contained in:
parent
1e4ce5055e
commit
be726e42b6
@ -359,10 +359,13 @@ export default class Generator {
|
||||
}
|
||||
|
||||
// Call hook to let user update the path & html
|
||||
const page = { route, path: fileName, html }
|
||||
const page = { route, path: fileName, html, exclude: false }
|
||||
await this.nuxt.callHook('generate:page', page)
|
||||
await this.nuxt.callHook('export:page', { page })
|
||||
await this.nuxt.callHook('export:page', { page, errors: pageErrors })
|
||||
|
||||
if (page.exclude) {
|
||||
return false
|
||||
}
|
||||
page.path = path.join(this.distPath, page.path)
|
||||
|
||||
// Make sure the sub folders are created
|
||||
|
@ -36,6 +36,11 @@ describe('basic generate', () => {
|
||||
nuxt.hook('generate:done', () => {
|
||||
writeFileSync(changedFileName, '')
|
||||
})
|
||||
nuxt.hook('export:page', ({ page, errors }) => {
|
||||
if (errors.length && page.route.includes('/skip-on-fail')) {
|
||||
page.exclude = true
|
||||
}
|
||||
})
|
||||
|
||||
builder = new Builder(nuxt)
|
||||
builder.build = jest.fn()
|
||||
@ -249,6 +254,16 @@ describe('basic generate', () => {
|
||||
expect(existsSync(resolve(distDir, '404.html'))).toBe(false)
|
||||
})
|
||||
|
||||
test('Checke skipped files', () => {
|
||||
expect(
|
||||
existsSync(resolve(distDir, 'skip-on-fail/fail.html'))
|
||||
).toBe(false)
|
||||
|
||||
expect(
|
||||
existsSync(resolve(distDir, 'skip-on-fail/success.html'))
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
afterAll(async () => {
|
||||
await server.close()
|
||||
|
2
test/fixtures/basic/nuxt.config.js
vendored
2
test/fixtures/basic/nuxt.config.js
vendored
@ -32,6 +32,8 @@ export default {
|
||||
'/users/1',
|
||||
'/users/2',
|
||||
'/тест雨',
|
||||
'/skip-on-fail/success',
|
||||
'/skip-on-fail/fail',
|
||||
{ route: '/users/3', payload: { id: 3000 } }
|
||||
],
|
||||
interval: 200
|
||||
|
11
test/fixtures/basic/pages/skip-on-fail/fail.vue
vendored
Normal file
11
test/fixtures/basic/pages/skip-on-fail/fail.vue
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<h1>404</h1>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
asyncData ({ error }) {
|
||||
error({ statusCode: 404, message: 'Post not found' })
|
||||
}
|
||||
}
|
||||
</script>
|
8
test/fixtures/basic/pages/skip-on-fail/success.vue
vendored
Normal file
8
test/fixtures/basic/pages/skip-on-fail/success.vue
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<template>
|
||||
<h1>200</h1>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user