From 84961b3dae5551c5581527cfb913a810e491d0a3 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Fri, 8 Dec 2017 17:32:55 +0800 Subject: [PATCH] feat: support component as js extension --- lib/builder/builder.js | 14 +++++++------- lib/common/utils.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 4d5e3bdb6d..a203242344 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -251,10 +251,10 @@ export default class Builder { // -- Layouts -- if (fs.existsSync(resolve(this.options.srcDir, 'layouts'))) { - const layoutsFiles = await glob('layouts/**/*.vue', { cwd: this.options.srcDir }) + const layoutsFiles = await glob('layouts/**/*.{vue,js}', { cwd: this.options.srcDir }) let hasErrorLayout = false layoutsFiles.forEach((file) => { - let name = file.split('/').slice(1).join('/').replace(/\.vue$/, '') + let name = file.split('/').slice(1).join('/').replace(/\.(vue|js)$/, '') if (name === 'error') { hasErrorLayout = true return @@ -277,7 +277,7 @@ export default class Builder { // If user defined a custom method to create routes if (this._nuxtPages) { // Use nuxt.js createRoutes bases on pages/ - const files = await glob('pages/**/*.vue', { cwd: this.options.srcDir }) + const files = await glob('pages/**/*.{vue,js}', { cwd: this.options.srcDir }) templateVars.router.routes = createRoutes(files, this.options.srcDir) } else { templateVars.router.routes = this.options.build.createRoutes(this.options.srcDir) @@ -534,14 +534,14 @@ export default class Builder { r(src, 'layouts'), r(src, 'store'), r(src, 'middleware'), - r(src, 'layouts/*.vue'), - r(src, 'layouts/**/*.vue') + r(src, 'layouts/*.{vue,js}'), + r(src, 'layouts/**/*.{vue,js}') ] if (this._nuxtPages) { patterns.push( r(src, 'pages'), - r(src, 'pages/*.vue'), - r(src, 'pages/**/*.vue') + r(src, 'pages/*.{vue,js}'), + r(src, 'pages/**/*.{vue,js}') ) } const options = Object.assign({}, this.options.watchers.chokidar, { diff --git a/lib/common/utils.js b/lib/common/utils.js index 20587828df..d8b9140589 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -212,13 +212,13 @@ export function cleanChildrenRoutes(routes, isChild = false) { export function createRoutes(files, srcDir) { let routes = [] files.forEach((file) => { - let keys = file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/{2,}/g, '/').split('/').slice(1) + let keys = file.replace(/^pages/, '').replace(/\.(vue|js)$/, '').replace(/\/{2,}/g, '/').split('/').slice(1) let route = { name: '', path: '', component: r(srcDir, file) } let parent = routes keys.forEach((key, i) => { route.name = route.name ? route.name + '-' + key.replace('_', '') : key.replace('_', '') route.name += (key === '_') ? 'all' : '' - route.chunkName = file.replace(/\.vue$/, '') + route.chunkName = file.replace(/\.(vue|js)$/, '') let child = _.find(parent, { name: route.name }) if (child) { child.children = child.children || []