mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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))
|
||||
})
|
||||
|
||||
const options = { components, buildDir: nuxt.options.buildDir }
|
||||
|
||||
addTemplate({
|
||||
...componentsTypeTemplate,
|
||||
options
|
||||
})
|
||||
|
||||
addTemplate({
|
||||
...componentsTemplate,
|
||||
options
|
||||
})
|
||||
|
||||
addPlugin({ src: '#build/components' })
|
||||
|
||||
// Scan components and add to plugin
|
||||
nuxt.hook('app:templates', async (app) => {
|
||||
components = await scanComponents(componentDirs, nuxt.options.srcDir!)
|
||||
nuxt.hook('app:templates', async () => {
|
||||
options.components = await scanComponents(componentDirs, nuxt.options.srcDir!)
|
||||
await nuxt.callHook('components:extend', components)
|
||||
|
||||
app.templates.push({
|
||||
...componentsTypeTemplate,
|
||||
options: { components, buildDir: nuxt.options.buildDir }
|
||||
})
|
||||
|
||||
if (!components.length) {
|
||||
return
|
||||
}
|
||||
|
||||
app.templates.push({
|
||||
...componentsTemplate,
|
||||
options: { components }
|
||||
})
|
||||
|
||||
app.plugins.push({ src: '#build/components' })
|
||||
await nuxt.callHook('builder:generateApp')
|
||||
})
|
||||
|
||||
nuxt.hook('prepare:types', ({ references }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user