Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How override plugins from Nuxt Layer in app? #27047

Open
lna1989 opened this issue May 3, 2024 Discussed in #25825 · 3 comments
Open

How override plugins from Nuxt Layer in app? #27047

lna1989 opened this issue May 3, 2024 Discussed in #25825 · 3 comments

Comments

@lna1989
Copy link

lna1989 commented May 3, 2024

Discussed in #25825

Originally posted by lna1989 February 16, 2024
'1.testPlugin.ts' plugin in the layer connected via an auto import and '1.testPlugin.ts' in App. layers connected to app in nuxt.config.ts.

Demo: https://stackblitz.com/edit/nuxt-starter-2r7whv?file=nuxt.config.ts

./layer/plugins/1.testPlugin.ts:

import { defineNuxtPlugin } from '#imports'

export default defineNuxtPlugin((nuxtApp) => {
  console.log('Layer testPlugin.ts')
})

./plugins/1.testPlugin.ts:

import { defineNuxtPlugin } from '#imports'

export default defineNuxtPlugin((nuxtApp) => {
  console.log('App testPlugin.ts')
})

The expected result: We see one message ("App testPlugin.ts'") from the App plugin in the console.
The actual result: We see two messages ("Layer testPlugin.ts'" and "'App testPlugin.ts'") in the console from both the layers plugin and the app.

Copy link

stackblitz bot commented May 3, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@markthree
Copy link

@lna1989 You can filter by hooks

// nuxt.config.ts
export default defineNuxtConfig({
  devtools: { enabled: false },
  extends: ["./layer"],
+  hooks: {
+    "app:resolve"(app) {
+      app.plugins = app.plugins.filter((p) =>
+        !p.src?.includes("layer/plugins/1.testPlugin.ts")
+      );
+    },
+  },
});

@danielroe
Copy link
Member

If we implement this in future we will likely use the object-syntax to allow deduplication:

export default defineNuxtPlugin({
  name: 'some-plugin',
  setup (nuxtApp) {
    // stuff
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants