nuxt / rfcs

RFCs for changes to Nuxt.js
96 stars 2 forks source link

Nuxt 3: Context changes #25

Closed Atinux closed 2 years ago

Atinux commented 5 years ago

With the new asyncData supporting this, we won't need the context to be given as argument.

Here's my proposal:

After talking with Pooya, I agree to remove env from the context since it's misleading and environment variables have a clear definition and use case for operating system. Also, since it's build with Webpack it can lead to secure informations leaked to client if misused.

App specific

Nuxt specific

App Config

Introducing this.$config, configurable:

This config will be also available with app.config for plugins.

Learn more on Nuxt Config improvements RFC

Nuxt plugins

This could also apply for plugins, but some plugins like nuxt-i18n to inject into app before instantiating it. See https://github.com/nuxt-community/nuxt-i18n/blob/master/src/plugins/main.js#L52

Since we can generate this context before instantiating the app, something like this could do the trick for plugins:

// ~/plugins/vue-i18n.js
export default (app, ctx, nuxt) {

}
// or?
export default ({ app, ctx, nuxt }) {

}

Let me know your thinking and if I missed some use cases (I'm sure I missed some).

kevinmarrec commented 5 years ago

Really nice proposal here @Atinux !

Could we simply omit this.$ctx.params & this.$ctx.query ? I mean, Is there any advantage besides having 2-characters shorter behavior than through this.$route ?

Atinux commented 5 years ago

You are right, I re-read it this morning and was like: This is USELESS 😄

Thanks @kevinmarrec, I updated the RFC

Timkor commented 5 years ago

Looks really cool. Maybe also interesting to take into account that the new async data can work with prefetching.

wpitallo commented 5 years ago

Will env variables still be set in nuxt.config.js?

vinayakkulkarni commented 3 years ago
export default ({ app, ctx, nuxt }) {

}

+1 for this.