mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 14:41:25 +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 { statSync } from 'fs'
|
||||||
import { resolve, basename } from 'pathe'
|
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 type { Component, ComponentsDir, ComponentsOptions } from '@nuxt/schema'
|
||||||
import { componentsTemplate, componentsTypeTemplate } from './templates'
|
import { componentsTemplate, componentsTypeTemplate } from './templates'
|
||||||
import { scanComponents } from './scan'
|
import { scanComponents } from './scan'
|
||||||
@ -22,7 +22,7 @@ export default defineNuxtModule<ComponentsOptions>({
|
|||||||
},
|
},
|
||||||
setup (componentOptions, nuxt) {
|
setup (componentOptions, nuxt) {
|
||||||
let componentDirs = []
|
let componentDirs = []
|
||||||
let components: Component[] = []
|
const components: Component[] = []
|
||||||
|
|
||||||
const normalizeDirs = (dir: any, cwd: string) => {
|
const normalizeDirs = (dir: any, cwd: string) => {
|
||||||
if (Array.isArray(dir)) {
|
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))
|
nuxt.options.build!.transpile!.push(...componentDirs.filter(dir => dir.transpile).map(dir => dir.path))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Scan components and add to plugin
|
const options = { components, buildDir: nuxt.options.buildDir }
|
||||||
nuxt.hook('app:templates', async (app) => {
|
|
||||||
components = await scanComponents(componentDirs, nuxt.options.srcDir!)
|
|
||||||
await nuxt.callHook('components:extend', components)
|
|
||||||
|
|
||||||
app.templates.push({
|
addTemplate({
|
||||||
...componentsTypeTemplate,
|
...componentsTypeTemplate,
|
||||||
options: { components, buildDir: nuxt.options.buildDir }
|
options
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!components.length) {
|
addTemplate({
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
app.templates.push({
|
|
||||||
...componentsTemplate,
|
...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 }) => {
|
nuxt.hook('prepare:types', ({ references }) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user