mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): load layer plugins before project plugins (#22889)
This commit is contained in:
parent
4e98ac1746
commit
89c4436ae1
@ -125,11 +125,11 @@ async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
|
||||
}))
|
||||
}
|
||||
|
||||
// Resolve plugins
|
||||
// Resolve plugins, first extended layers and then base
|
||||
app.plugins = [
|
||||
...nuxt.options.plugins.map(normalizePlugin)
|
||||
]
|
||||
for (const config of nuxt.options._layers.map(layer => layer.config)) {
|
||||
for (const config of nuxt.options._layers.map(layer => layer.config).reverse()) {
|
||||
app.plugins.push(...[
|
||||
...(config.plugins || []),
|
||||
...config.srcDir
|
||||
|
@ -983,6 +983,11 @@ describe('extends support', () => {
|
||||
const html = await $fetch('/foo')
|
||||
expect(html).toContain('Plugin | foo: String generated from foo plugin!')
|
||||
})
|
||||
|
||||
it('respects plugin ordering within layers', async () => {
|
||||
const html = await $fetch('/plugins/ordering')
|
||||
expect(html).toContain('catchall at plugins')
|
||||
})
|
||||
})
|
||||
|
||||
describe('server', () => {
|
||||
|
3
test/fixtures/basic/extends/bar/plugins/09.layer-plugin-pre.ts
vendored
Normal file
3
test/fixtures/basic/extends/bar/plugins/09.layer-plugin-pre.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.provide('layerPluginPre', 'layer-plugin')
|
||||
})
|
3
test/fixtures/basic/extends/bar/plugins/11.layer-plugin-post.ts
vendored
Normal file
3
test/fixtures/basic/extends/bar/plugins/11.layer-plugin-post.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.provide('layerPluginPost', 'layer-plugin')
|
||||
})
|
10
test/fixtures/basic/plugins/10.layer-ordering.ts
vendored
Normal file
10
test/fixtures/basic/plugins/10.layer-ordering.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
if (useRoute().path === '/plugins/ordering') {
|
||||
if (!nuxtApp.$layerPluginPre) {
|
||||
throw createError('layer plugin failed to run before end project plugin')
|
||||
}
|
||||
if (!nuxtApp.$layerPluginPost) {
|
||||
throw createError('layer plugin failed to run before end project plugin')
|
||||
}
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user