#What is `enforce` option in plugin ?
21 messages · Page 1 of 1 (latest)
i think this helps enforce the position of a plugin
but from the nuxt3 docs, seems like using it might actually interfere with optimizations that nuxt might perform
quoting from here :
"https://nuxt.com/docs/guide/directory-structure/plugins#object-syntax-plugins"
"If you are using the object-syntax, the properties may be statically analyzed in future to produce a more optimized build. So you should not define them at runtime.
For example, setting enforce: process.server ? 'pre' : 'post' would defeat any future optimization Nuxt is able to do for your plugins."
thanks... I don’t understand why the doc puts it up front without explaining it properly
source code says that
This allows more granular control over plugin order and should only be used by advanced users. It overrides the value of enforce and is used to sort plugins.
like i said : "i think this helps enforce the position of a plugin"
but i think you're overthinking it... like do you really need it or are you just exploring advanced topics?
the later
especially because it’s right there in the documentation
and I wanted to understand what it was
so many things in the documenttion that i never encounter, or get 😂
because I’d assume it’s important
but quite the contrary it would be reserved for very specific usecases
so yeah... if I do something like nuxtApp.foo = 1 and nuxtApp.foo = 2 in 2 plugins
foo will have a value of either 1 or 2 depending on the enforce thing
so it will persist the value in the enforced plugin?