Closed aballet closed 10 months ago
Here is the relevant docs: https://nuxt.com/docs/guide/going-further/modules#exposing-options-to-runtime
I think we would want to use defu
to set the default values in runtime config to what was set in app config. Then we need to change the access token given to mapbox to the one in the runtime config instead.
Keep in mind for this to work, we probably will need to watch the access token and reinitialize mapbox with it once it changes.
Personally, I would get the access token on build from different env files, and use a different build step for each environment. Runtime config seems like an interesting feature though, perhaps all the mapboxgl
options should be provided at runtime for easier access.
Added in #73
Hello,
I am developing an application that will be deployed to multiple environments (development, staging, production...). I have an access token for each environment. Currently, I did not find a workaround for setting the access token at runtime, once my app is built.
I suggest using the runtimeConfig field in nuxt.config.ts:
This way, we can set the access token at runtime using the environment variable NUXT_PUBLIC_MAPBOX_ACCESS_TOKEN.
In order not to break things, there can be an order of precedence: first the appConfig, then the runtimeConfig if the field is empty in the appConfig.
What do you think? I'm not an expert in module development, but I can give it a try with a PR.