mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-18 02:07:14 +00:00
Allow modules to provide their createRoutes
This commit is contained in:
parent
8f08f13941
commit
f5541999fd
19
lib/build.js
19
lib/build.js
@ -98,13 +98,15 @@ export function options () {
|
||||
|
||||
export async function build () {
|
||||
// Check if pages dir exists and warn if not
|
||||
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
|
||||
} else {
|
||||
console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') // eslint-disable-line no-console
|
||||
if (typeof this.createRoutes !== 'function') {
|
||||
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
|
||||
} else {
|
||||
console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') // eslint-disable-line no-console
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
debug(`App root: ${this.srcDir}`)
|
||||
debug('Generating .nuxt/ files...')
|
||||
@ -214,9 +216,12 @@ async function generateRoutesAndFiles () {
|
||||
// -- Routes --
|
||||
debug('Generating routes...')
|
||||
// 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})
|
||||
templateVars.router.routes = createRoutes(files, this.srcDir)
|
||||
} else {
|
||||
templateVars.router.routes = this.createRoutes.call(this, this.srcDir)
|
||||
}
|
||||
if (typeof this.options.router.extendRoutes === 'function') {
|
||||
// let the user extend the routes
|
||||
|
Loading…
Reference in New Issue
Block a user