#What is `enforce` option in plugin ?

21 messages · Page 1 of 1 (latest)

stone halo
#

From the source code it seems that it is related to plugin execution order. But from my tests I see no real difference... what is this option doing ?

nimble pebble
#

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."

Nuxt

Nuxt has a plugins system to use Vue plugins and more at the creation of your Vue application.

stone halo
#

thanks... I don’t understand why the doc puts it up front without explaining it properly

stone halo
nimble pebble
#

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?

nimble pebble
#

ah . nice 😄

#

i was wondering

stone halo
#

especially because it’s right there in the documentation

#

and I wanted to understand what it was

nimble pebble
#

so many things in the documenttion that i never encounter, or get 😂

stone halo
#

because I’d assume it’s important

#

but quite the contrary it would be reserved for very specific usecases

nimble pebble
#

the same concept exists in vite

stone halo
#

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

nimble pebble
#

so it will persist the value in the enforced plugin?