feat(nuxt3): allow manually enabling/disabling the ad-hoc pages module (#4327)

This commit is contained in:
Daniel Roe 2022-04-13 18:18:51 +01:00 committed by GitHub
parent a89d2f9c1a
commit f4fb9160c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -9,15 +9,15 @@ import { TransformMacroPlugin, TransformMacroPluginOptions } from './macros'
export default defineNuxtModule({ export default defineNuxtModule({
meta: { meta: {
name: 'router' name: 'pages'
}, },
setup (_options, nuxt) { setup (_options, nuxt) {
const pagesDirs = nuxt.options._layers.map( const pagesDirs = nuxt.options._layers.map(
layer => resolve(layer.config.srcDir, layer.config.dir?.pages || 'pages') layer => resolve(layer.config.srcDir, layer.config.dir?.pages || 'pages')
) )
// Disable module (and use universal router) if pages dir do not exists // Disable module (and use universal router) if pages dir do not exists or user has disabled it
if (!pagesDirs.some(dir => existsSync(dir))) { if (nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) {
addPlugin(resolve(distDir, 'app/plugins/router')) addPlugin(resolve(distDir, 'app/plugins/router'))
return return
} }

View File

@ -35,4 +35,13 @@ export default {
global: false, global: false,
dirs: [] dirs: []
}, },
/**
* Whether to use the vue-router integration in Nuxt 3. If you do not provide a value it will be
* enabled if you have a `pages/` directory in your source folder.
*
* @type {boolean}
* @version 3
*/
pages: undefined
} }