Open raphaelbernhart opened 1 year ago
Nuxt Modules are run during build, and Nuxt Plugins are run at the creation of the nuxtApp before anything else. So I believe it won't be possible to disable a module during runtime, but it should possible to control plugins.
For your specific example of Google Analytics (I don't use it), the Nuxt doc suggests the use of a vue plugin within a Nuxt plugin; so not via a module.
To enable or disable plugins or pieces of codes that rely on cookies, I guess the vanilla methods wont be usable, nor the script directives as you can't add scripts that way in Nuxt. But I was thinking you could develop some kind of mechanism using a Composable or a Pinia Store that you could expose. Would still require some manual work (plugin-by-plugin or pieceOfCode-by-pieceOfCodes), but it would be greatly facilitated.
Is that of any inspiration?
Nuxt Modules are run during build, and Nuxt Plugins are run at the creation of the nuxtApp before anything else. So I believe it won't be possible to disable a module during runtime, but it should possible to control plugins.
For your specific example of Google Analytics (I don't use it), the Nuxt doc suggests the use of a vue plugin within a Nuxt plugin; so not via a module.
To enable or disable plugins or pieces of codes that rely on cookies, I guess the vanilla methods wont be usable, nor the script directives as you can't add scripts that way in Nuxt. But I was thinking you could develop some kind of mechanism using a Composable or a Pinia Store that you could expose. Would still require some manual work (plugin-by-plugin or pieceOfCode-by-pieceOfCodes), but it would be greatly facilitated.
Is that of any inspiration?
Thanks for the detailed response.
Thats also what I thought. I will take a look and try to come up with something.
I think the problem with the pinia store is that you then have a dependency module (pinia) every user of the module has to install which I don't want. Maybe I can implement a custom store and work with states.
Thanks anyway and I hope you will keep track of the project :)
I understand your philosophy !
Will certainly follow your development :)) Haven't actually tried to implement your package yet, as time does not allow for the moment, but will soon
Problem
In the module creation process I encountered one major error. When using the module the developers themselves do have to handle the script execution. When having a vanilla js site this is no problem because the underlying library has a feature for this. But when working with nuxt this is not posibble because nuxt uses webpack / vite to compile.
Let me give an example:
I want to use Google Analytics in my project. So I -> Install and configure the module but now the tracking already happens on page load because the module (and plugin) gets initialized on nuxt build. To prevent this the developer has to handle the blocking of the tracking by himself.
Possible Solution
Add a feature to only load the modules / plugins after the client accepts certain categories. I already tired this with installing the modules after accept but this is not possible. I think this would be possible with plugins as plugins can also be installed after the nuxt build (to my knowledge).
If anyone has a better solution for the problem itself or the module installation problem please feel free to propose it.