mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
refactor: vue takes precedence over js in pages and layouts
This commit is contained in:
parent
a4e2a7cd65
commit
bc3bcac337
@ -271,7 +271,9 @@ module.exports = class Builder {
|
|||||||
hasErrorLayout = true
|
hasErrorLayout = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
templateVars.layouts[name] = this.relativeToBuild(this.options.srcDir, file)
|
if (!templateVars.layouts[name] || /\.vue$/.test(file)) {
|
||||||
|
templateVars.layouts[name] = this.relativeToBuild(this.options.srcDir, file)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if (!templateVars.components.ErrorPage && hasErrorLayout) {
|
if (!templateVars.components.ErrorPage && hasErrorLayout) {
|
||||||
templateVars.components.ErrorPage = this.relativeToBuild(this.options.srcDir, 'layouts/error.vue')
|
templateVars.components.ErrorPage = this.relativeToBuild(this.options.srcDir, 'layouts/error.vue')
|
||||||
@ -289,8 +291,14 @@ module.exports = 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,js}', { cwd: this.options.srcDir })
|
const files = {};
|
||||||
templateVars.router.routes = createRoutes(files, this.options.srcDir)
|
(await glob('pages/**/*.{vue,js}', { cwd: this.options.srcDir })).forEach(f => {
|
||||||
|
const key = f.replace(/\.(js|vue)$/, '')
|
||||||
|
if (/\.vue$/.test(f) || !files[key]) {
|
||||||
|
files[key] = f
|
||||||
|
}
|
||||||
|
})
|
||||||
|
templateVars.router.routes = createRoutes(Object.values(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)
|
||||||
}
|
}
|
||||||
|
@ -250,6 +250,11 @@ test('/jsx', async t => {
|
|||||||
t.true(html.includes('<h1>JSX Page</h1>'))
|
t.true(html.includes('<h1>JSX Page</h1>'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('/js-link', async t => {
|
||||||
|
const { html } = await nuxt.renderRoute('/js-link')
|
||||||
|
t.true(html.includes('<h1>vue file is first-class</h1>'))
|
||||||
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test.after('Closing server and nuxt.js', t => {
|
test.after('Closing server and nuxt.js', t => {
|
||||||
nuxt.close()
|
nuxt.close()
|
||||||
|
2
test/fixtures/basic/pages/js-link.js
vendored
Normal file
2
test/fixtures/basic/pages/js-link.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export default {
|
||||||
|
}
|
5
test/fixtures/basic/pages/js-link.vue
vendored
Normal file
5
test/fixtures/basic/pages/js-link.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<h1>vue file is first-class</h1>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script src="./js-link.js"></script>
|
Loading…
Reference in New Issue
Block a user