How to load env variables for a Nuxt project in a monorepo
When working on project that use a monorepo with Nuxt Layers, we will need to load
environment variables that are located on the root of the project:
- Project-root
- packages
- shared-ui
- shared-auth
- shared-content
- main-app
-.env -> use this for all the layers
The solution for this problem is really:
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev --dotenv ../../.env",//<- put the path of your env file
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
}
For build and other scripts, this will be the same as well.
Please if anyone have a better way please comment below and let's learn together
Can someone submit this article to the Daily dev, I can't do my self no enough reputation just 10 at the moment
Top comments (2)
This is pretty informative! Just a quick questionβhow does this approach handle different environments like staging or production?
You can create a script on the package json
github.com/leamsigc/nuxt-monorepo-...
example: