mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 17:07:22 +00:00
fix(nuxt3): don't add superfluous templates (#3366)
This commit is contained in:
parent
271289c4d6
commit
ac63401700
@ -1,6 +1,6 @@
|
||||
import { statSync } from 'fs'
|
||||
import { resolve, basename } from 'pathe'
|
||||
import { defineNuxtModule, resolveAlias, addVitePlugin, addWebpackPlugin } from '@nuxt/kit'
|
||||
import { defineNuxtModule, resolveAlias, addVitePlugin, addWebpackPlugin, addTemplate, addPlugin } from '@nuxt/kit'
|
||||
import type { Component, ComponentsDir, ComponentsOptions } from '@nuxt/schema'
|
||||
import { componentsTemplate, componentsTypeTemplate } from './templates'
|
||||
import { scanComponents } from './scan'
|
||||
@ -22,7 +22,7 @@ export default defineNuxtModule<ComponentsOptions>({
|
||||
},
|
||||
setup (componentOptions, nuxt) {
|
||||
let componentDirs = []
|
||||
let components: Component[] = []
|
||||
const components: Component[] = []
|
||||
|
||||
const normalizeDirs = (dir: any, cwd: string) => {
|
||||
if (Array.isArray(dir)) {
|
||||
@ -99,26 +99,25 @@ export default defineNuxtModule<ComponentsOptions>({
|
||||
nuxt.options.build!.transpile!.push(...componentDirs.filter(dir => dir.transpile).map(dir => dir.path))
|
||||
})
|
||||
|
||||
// Scan components and add to plugin
|
||||
nuxt.hook('app:templates', async (app) => {
|
||||
components = await scanComponents(componentDirs, nuxt.options.srcDir!)
|
||||
await nuxt.callHook('components:extend', components)
|
||||
const options = { components, buildDir: nuxt.options.buildDir }
|
||||
|
||||
app.templates.push({
|
||||
addTemplate({
|
||||
...componentsTypeTemplate,
|
||||
options: { components, buildDir: nuxt.options.buildDir }
|
||||
options
|
||||
})
|
||||
|
||||
if (!components.length) {
|
||||
return
|
||||
}
|
||||
|
||||
app.templates.push({
|
||||
addTemplate({
|
||||
...componentsTemplate,
|
||||
options: { components }
|
||||
options
|
||||
})
|
||||
|
||||
app.plugins.push({ src: '#build/components' })
|
||||
addPlugin({ src: '#build/components' })
|
||||
|
||||
// Scan components and add to plugin
|
||||
nuxt.hook('app:templates', async () => {
|
||||
options.components = await scanComponents(componentDirs, nuxt.options.srcDir!)
|
||||
await nuxt.callHook('components:extend', components)
|
||||
await nuxt.callHook('builder:generateApp')
|
||||
})
|
||||
|
||||
nuxt.hook('prepare:types', ({ references }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user