mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
parent
7fa5fb0a58
commit
6a6794e020
@ -60,6 +60,7 @@
|
||||
"dependencies": {
|
||||
"@nuxt/builder": "2.12.1",
|
||||
"@nuxt/cli": "2.12.1",
|
||||
"@nuxt/components": "^0.2.2",
|
||||
"@nuxt/core": "2.12.1",
|
||||
"@nuxt/generator": "2.12.1",
|
||||
"@nuxt/loading-screen": "^1.2.0",
|
||||
|
@ -448,6 +448,11 @@ export function getNuxtConfig (_options) {
|
||||
.map(([path, handler]) => ({ path, handler }))
|
||||
}
|
||||
|
||||
// Components module
|
||||
if (options.components) {
|
||||
options.buildModules.push('@nuxt/components')
|
||||
}
|
||||
|
||||
// Generate staticAssets
|
||||
const { staticAssets } = options.generate
|
||||
if (!staticAssets.version) {
|
||||
|
@ -112,10 +112,10 @@ export default class ModuleContainer {
|
||||
}
|
||||
|
||||
requireModule (moduleOpts) {
|
||||
return this.addModule(moduleOpts, true /* require once */)
|
||||
return this.addModule(moduleOpts)
|
||||
}
|
||||
|
||||
async addModule (moduleOpts, requireOnce) {
|
||||
async addModule (moduleOpts) {
|
||||
let src
|
||||
let options
|
||||
let handler
|
||||
@ -176,15 +176,10 @@ export default class ModuleContainer {
|
||||
throw new TypeError('Module should export a function: ' + src)
|
||||
}
|
||||
|
||||
// Resolve module meta
|
||||
let key = (handler.meta && handler.meta.name) || handler.name
|
||||
if (!key || key === 'default') {
|
||||
key = src
|
||||
}
|
||||
|
||||
// Update requiredModules
|
||||
// Ensure module is required once
|
||||
const key = (handler.meta && handler.meta.name) || src
|
||||
if (typeof key === 'string') {
|
||||
if (requireOnce && this.requiredModules[key]) {
|
||||
if (this.requiredModules[key]) {
|
||||
return
|
||||
}
|
||||
this.requiredModules[key] = { src, options, handler }
|
||||
|
@ -317,7 +317,7 @@ describe('core: module', () => {
|
||||
module.requireModule(moduleOpts)
|
||||
|
||||
expect(module.addModule).toBeCalledTimes(1)
|
||||
expect(module.addModule).toBeCalledWith(moduleOpts, true)
|
||||
expect(module.addModule).toBeCalledWith(moduleOpts)
|
||||
})
|
||||
|
||||
test('should add string module', async () => {
|
||||
@ -402,21 +402,17 @@ describe('core: module', () => {
|
||||
})
|
||||
|
||||
const result = await module.addModule({
|
||||
src: 'moduleTest',
|
||||
src: 'pathToModule',
|
||||
options: { test: true },
|
||||
handler: function objectModule (options) {
|
||||
return Promise.resolve(options)
|
||||
}
|
||||
handler: opts => opts
|
||||
})
|
||||
|
||||
expect(requireModule).not.toBeCalled()
|
||||
expect(module.requiredModules).toEqual({
|
||||
objectModule: {
|
||||
handler: expect.any(Function),
|
||||
options: {
|
||||
test: true
|
||||
},
|
||||
src: 'moduleTest'
|
||||
pathToModule: {
|
||||
src: 'pathToModule',
|
||||
options: { test: true },
|
||||
handler: expect.any(Function)
|
||||
}
|
||||
})
|
||||
expect(result).toEqual({ test: true })
|
||||
|
@ -370,6 +370,11 @@ describe('basic ssr', () => {
|
||||
expect(html).toContain('<h1>Nested symlink page</h1>')
|
||||
})
|
||||
|
||||
test('/components', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/components')
|
||||
expect(html).toContain('Auto discovered component!')
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
afterAll(async () => {
|
||||
await nuxt.close()
|
||||
|
3
test/fixtures/basic/components/MyComponent.vue
vendored
Normal file
3
test/fixtures/basic/components/MyComponent.vue
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<div>Auto discovered component!</div>
|
||||
</template>
|
1
test/fixtures/basic/nuxt.config.js
vendored
1
test/fixtures/basic/nuxt.config.js
vendored
@ -63,6 +63,7 @@ export default {
|
||||
'': true
|
||||
},
|
||||
pageTransition: false,
|
||||
components: true,
|
||||
plugins: [
|
||||
'~/plugins/vuex-module',
|
||||
'~/plugins/dir-plugin',
|
||||
|
5
test/fixtures/basic/pages/components.vue
vendored
Normal file
5
test/fixtures/basic/pages/components.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
<MyComponent />
|
||||
</div>
|
||||
</template>
|
@ -1819,6 +1819,11 @@
|
||||
"@nodelib/fs.scandir" "2.1.3"
|
||||
fastq "^1.6.0"
|
||||
|
||||
"@nuxt/components@^0.2.2":
|
||||
version "0.2.2"
|
||||
resolved "https://registry.npmjs.org/@nuxt/components/-/components-0.2.2.tgz#194f65574dc40aacf8d0f132a134168ce1b58c83"
|
||||
integrity sha512-mTDZLmfx65fuI8haXZLeh425vSrCAHRGyK3G6Ckr/QSgmle9HDuaQX1Jl/yEEvBxiUzcPp1fhMexNMn2mvkofg==
|
||||
|
||||
"@nuxt/devalue@^1.2.4":
|
||||
version "1.2.4"
|
||||
resolved "https://registry.npmjs.org/@nuxt/devalue/-/devalue-1.2.4.tgz#69eca032b7481fd3c019a78ade65d642da3f2f35"
|
||||
|
Loading…
Reference in New Issue
Block a user