-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Nuxt 3 compatibility #9
Comments
Any update on this? Would be helpful if there is a guide/example similar to this - https://axe.vue-a11y.com/guide/#nuxt-js |
Create a client side plugin,
Then you need to render the popup component somewhere in your app for it to display, in a root component or a layout perhaps?
Make sure you only show it after the component has been mounted, the |
When using Nuxt with Vite, this can be further simplefied inside the component:
|
I was able to get it to load, but I was not able to get nuxt to ignore it for production builds. Anyone got any ideas for that? I've tried adding it as a dev-only component, and it didn't load the component, but something is still requiring that the package is added to the bundle. |
Edit: This does not remove it from bundling - see solution from Harm-Nullix below. @Djeisen642 // plugins/axe.client.ts
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueAxe);
}); If that does not work for you, try logging your |
The following setup works fine for me for only included it in development: export default defineNuxtConfig({
vite: {
optimizeDeps: { include: [...(process.env.NODE_ENV === 'development' ? ['axe-core'] : [])] },
},
runtimeConfig: {
public: {
env: process.env.NODE_ENV || 'development',
}
},
}) plugins/a11y.client.ts : import { useRawConfig } from '~/frontend/composables/useConfig'
export default defineNuxtPlugin(async (nuxtApp) => {
const config = useRuntimeConfig()
if (config.public.env === 'development') {
// @ts-ignore import has no types
void import('vue-axe').then((vueAxe) => {
nuxtApp.vueApp.component('VueAxePopup', vueAxe.VueAxePopup)
nuxtApp.vueApp.use(vueAxe.default, {
auto: false,
})
})
} else {
nuxtApp.vueApp.component('VueAxePopup', h('div'))
}
}) package.json : {
"devDependencies": {
"axe-core": "4.7.2",
"nuxt": "3.6.5",
"vue-axe": "3.1.2",
},
} And then just always mount it in app.vue : <template>
<nuxt-layout>
<nuxt-loading-indicator />
<nuxt-page />
<vue-axe-popup />
</nuxt-layout>
</template> |
Hello is this compatible with Nuxt 3?
I tried to create a nuxt plugin like this, but without results:
The text was updated successfully, but these errors were encountered: