feat: support component as js extension

This commit is contained in:
Clark Du 2017-12-08 17:32:55 +08:00
parent 0b9cd1b408
commit 84961b3dae
2 changed files with 9 additions and 9 deletions

View File

@ -251,10 +251,10 @@ export default class Builder {
// -- Layouts -- // -- Layouts --
if (fs.existsSync(resolve(this.options.srcDir, '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 let hasErrorLayout = false
layoutsFiles.forEach((file) => { 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') { if (name === 'error') {
hasErrorLayout = true hasErrorLayout = true
return return
@ -277,7 +277,7 @@ export default class Builder {
// If user defined a custom method to create routes // If user defined a custom method to create routes
if (this._nuxtPages) { if (this._nuxtPages) {
// Use nuxt.js createRoutes bases on pages/ // 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) templateVars.router.routes = createRoutes(files, this.options.srcDir)
} else { } else {
templateVars.router.routes = this.options.build.createRoutes(this.options.srcDir) templateVars.router.routes = this.options.build.createRoutes(this.options.srcDir)
@ -534,14 +534,14 @@ export default class Builder {
r(src, 'layouts'), r(src, 'layouts'),
r(src, 'store'), r(src, 'store'),
r(src, 'middleware'), r(src, 'middleware'),
r(src, 'layouts/*.vue'), r(src, 'layouts/*.{vue,js}'),
r(src, 'layouts/**/*.vue') r(src, 'layouts/**/*.{vue,js}')
] ]
if (this._nuxtPages) { if (this._nuxtPages) {
patterns.push( patterns.push(
r(src, 'pages'), r(src, 'pages'),
r(src, 'pages/*.vue'), r(src, 'pages/*.{vue,js}'),
r(src, 'pages/**/*.vue') r(src, 'pages/**/*.{vue,js}')
) )
} }
const options = Object.assign({}, this.options.watchers.chokidar, { const options = Object.assign({}, this.options.watchers.chokidar, {

View File

@ -212,13 +212,13 @@ export function cleanChildrenRoutes(routes, isChild = false) {
export function createRoutes(files, srcDir) { export function createRoutes(files, srcDir) {
let routes = [] let routes = []
files.forEach((file) => { 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 route = { name: '', path: '', component: r(srcDir, file) }
let parent = routes let parent = routes
keys.forEach((key, i) => { keys.forEach((key, i) => {
route.name = route.name ? route.name + '-' + key.replace('_', '') : key.replace('_', '') route.name = route.name ? route.name + '-' + key.replace('_', '') : key.replace('_', '')
route.name += (key === '_') ? 'all' : '' route.name += (key === '_') ? 'all' : ''
route.chunkName = file.replace(/\.vue$/, '') route.chunkName = file.replace(/\.(vue|js)$/, '')
let child = _.find(parent, { name: route.name }) let child = _.find(parent, { name: route.name })
if (child) { if (child) {
child.children = child.children || [] child.children = child.children || []