fix(nuxt): respect layer order for other layer plugins (#23148)

This commit is contained in:
Daniel Roe 2023-09-12 15:24:35 +01:00 committed by GitHub
parent 2a21059495
commit a4cf8a0c24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,9 +126,7 @@ async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
}
// Resolve plugins, first extended layers and then base
app.plugins = [
...nuxt.options.plugins.map(normalizePlugin)
]
app.plugins = []
for (const config of nuxt.options._layers.map(layer => layer.config).reverse()) {
app.plugins.push(...[
...(config.plugins || []),
@ -141,6 +139,14 @@ async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
].map(plugin => normalizePlugin(plugin as NuxtPlugin)))
}
// Add back plugins not specified in layers or user config
for (const p of nuxt.options.plugins) {
const plugin = normalizePlugin(p)
if (!app.plugins.some(p => p.src === plugin.src)) {
app.plugins.unshift(plugin)
}
}
// Normalize and de-duplicate plugins and middleware
app.middleware = uniqueBy(await resolvePaths(app.middleware, 'path'), 'name')
app.plugins = uniqueBy(await resolvePaths(app.plugins, 'src'), 'src')