mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-04 11:27:13 +00:00
fix(kit,nuxt): provide buildDir
to normalizeTemplate
(#30115)
This commit is contained in:
parent
e27cc5aef9
commit
9275b2a7be
@ -23,8 +23,7 @@ export function addTemplate<T> (_template: NuxtTemplate<T> | string) {
|
|||||||
const template = normalizeTemplate(_template)
|
const template = normalizeTemplate(_template)
|
||||||
|
|
||||||
// Remove any existing template with the same destination path
|
// Remove any existing template with the same destination path
|
||||||
nuxt.options.build.templates = nuxt.options.build.templates
|
nuxt.options.build.templates = nuxt.options.build.templates.filter(p => normalizeTemplate(p).dst !== template.dst)
|
||||||
.filter(p => normalizeTemplate(p).dst !== template.dst)
|
|
||||||
|
|
||||||
// Add to templates array
|
// Add to templates array
|
||||||
nuxt.options.build.templates.push(template)
|
nuxt.options.build.templates.push(template)
|
||||||
@ -68,7 +67,7 @@ export function addTypeTemplate<T> (_template: NuxtTypeTemplate<T>) {
|
|||||||
/**
|
/**
|
||||||
* Normalize a nuxt template object
|
* Normalize a nuxt template object
|
||||||
*/
|
*/
|
||||||
export function normalizeTemplate<T> (template: NuxtTemplate<T> | string): ResolvedNuxtTemplate<T> {
|
export function normalizeTemplate<T> (template: NuxtTemplate<T> | string, buildDir?: string): ResolvedNuxtTemplate<T> {
|
||||||
if (!template) {
|
if (!template) {
|
||||||
throw new Error('Invalid template: ' + JSON.stringify(template))
|
throw new Error('Invalid template: ' + JSON.stringify(template))
|
||||||
}
|
}
|
||||||
@ -87,17 +86,16 @@ export function normalizeTemplate<T> (template: NuxtTemplate<T> | string): Resol
|
|||||||
}
|
}
|
||||||
if (!template.filename) {
|
if (!template.filename) {
|
||||||
const srcPath = parse(template.src)
|
const srcPath = parse(template.src)
|
||||||
template.filename = (template as any).fileName ||
|
template.filename = (template as any).fileName || `${basename(srcPath.dir)}.${srcPath.name}.${hash(template.src)}${srcPath.ext}`
|
||||||
`${basename(srcPath.dir)}.${srcPath.name}.${hash(template.src)}${srcPath.ext}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!template.src && !template.getContents) {
|
if (!template.src && !template.getContents) {
|
||||||
throw new Error('Invalid template. Either getContents or src options should be provided: ' + JSON.stringify(template))
|
throw new Error('Invalid template. Either `getContents` or `src` should be provided: ' + JSON.stringify(template))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!template.filename) {
|
if (!template.filename) {
|
||||||
throw new Error('Invalid template. Either filename should be provided: ' + JSON.stringify(template))
|
throw new Error('Invalid template. `filename` must be provided: ' + JSON.stringify(template))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always write declaration files
|
// Always write declaration files
|
||||||
@ -107,8 +105,7 @@ export function normalizeTemplate<T> (template: NuxtTemplate<T> | string): Resol
|
|||||||
|
|
||||||
// Resolve dst
|
// Resolve dst
|
||||||
if (!template.dst) {
|
if (!template.dst) {
|
||||||
const nuxt = useNuxt()
|
template.dst = resolve(buildDir ?? useNuxt().options.buildDir, template.filename)
|
||||||
template.dst = resolve(nuxt.options.buildDir, template.filename)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return template as ResolvedNuxtTemplate<T>
|
return template as ResolvedNuxtTemplate<T>
|
||||||
|
@ -37,7 +37,7 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?:
|
|||||||
await nuxt.callHook('app:templates', app)
|
await nuxt.callHook('app:templates', app)
|
||||||
|
|
||||||
// Normalize templates
|
// Normalize templates
|
||||||
app.templates = app.templates.map(tmpl => normalizeTemplate(tmpl))
|
app.templates = app.templates.map(tmpl => normalizeTemplate(tmpl, nuxt.options.buildDir))
|
||||||
|
|
||||||
// compile plugins first as they are needed within the nuxt.vfs
|
// compile plugins first as they are needed within the nuxt.vfs
|
||||||
// in order to annotate templated plugins
|
// in order to annotate templated plugins
|
||||||
|
Loading…
Reference in New Issue
Block a user