I have a custom plugin that should only run on production so I need to only load it when in that environment. Is there a way in nuxt.config.js to do that?
The solution with build.extend no longer works for me.
Here is what I've come up with...
in nuxt.config.js:
plugins: [
{ src: '~/plugins/my-plugin-1.js' },
{ src: '~/plugins/my-plugin-2.client.js' },
// Add plugins that should only run in production.
...(process.env.NODE_ENV === 'production' ? [
{ src: '~/plugins/my-production-plugin-1.client.js' }
] : []),
],
It looks like the solution is in the build configuration of nuxt.config.js:
module.exports = {
...
build: {
extend (config, { isDev, isClient }) {
if (!isDev && isClient) {
config.plugins.push({src: '@/plugins/myPlugin', ssr: false})
}
}
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With