diff --git a/lib/build.js b/lib/build.js index 4f255db972..7ebb48ff79 100644 --- a/lib/build.js +++ b/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