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