mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 06:35:10 +00:00
Allow modules to provide their createRoutes
This commit is contained in:
parent
8f08f13941
commit
f5541999fd
@ -98,6 +98,7 @@ export function options () {
|
|||||||
|
|
||||||
export async function build () {
|
export async function build () {
|
||||||
// Check if pages dir exists and warn if not
|
// Check if pages dir exists and warn if not
|
||||||
|
if (typeof this.createRoutes !== 'function') {
|
||||||
if (!fs.existsSync(join(this.srcDir, 'pages'))) {
|
if (!fs.existsSync(join(this.srcDir, 'pages'))) {
|
||||||
if (fs.existsSync(join(this.srcDir, '..', 'pages'))) {
|
if (fs.existsSync(join(this.srcDir, '..', 'pages'))) {
|
||||||
console.error('> No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?') // eslint-disable-line no-console
|
console.error('> No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?') // eslint-disable-line no-console
|
||||||
@ -106,6 +107,7 @@ export async function build () {
|
|||||||
}
|
}
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
debug(`App root: ${this.srcDir}`)
|
debug(`App root: ${this.srcDir}`)
|
||||||
debug('Generating .nuxt/ files...')
|
debug('Generating .nuxt/ files...')
|
||||||
// Create .nuxt/, .nuxt/components and .nuxt/dist folders
|
// Create .nuxt/, .nuxt/components and .nuxt/dist folders
|
||||||
@ -214,9 +216,12 @@ async function generateRoutesAndFiles () {
|
|||||||
// -- Routes --
|
// -- Routes --
|
||||||
debug('Generating routes...')
|
debug('Generating routes...')
|
||||||
// Format routes for the lib/app/router.js template
|
// Format routes for the lib/app/router.js template
|
||||||
if (fs.existsSync(resolve(this.srcDir, 'pages'))) {
|
if (typeof this.createRoutes !== 'function') {
|
||||||
|
// Use internal createRoutes
|
||||||
const files = await glob('pages/**/*.vue', {cwd: this.srcDir})
|
const files = await glob('pages/**/*.vue', {cwd: this.srcDir})
|
||||||
templateVars.router.routes = createRoutes(files, this.srcDir)
|
templateVars.router.routes = createRoutes(files, this.srcDir)
|
||||||
|
} else {
|
||||||
|
templateVars.router.routes = this.createRoutes.call(this, this.srcDir)
|
||||||
}
|
}
|
||||||
if (typeof this.options.router.extendRoutes === 'function') {
|
if (typeof this.options.router.extendRoutes === 'function') {
|
||||||
// let the user extend the routes
|
// let the user extend the routes
|
||||||
|
Loading…
Reference in New Issue
Block a user