mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
feat: support component as js extension
This commit is contained in:
parent
0b9cd1b408
commit
84961b3dae
@ -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, {
|
||||
|
@ -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 || []
|
||||
|
Loading…
Reference in New Issue
Block a user