Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nx and Vite handling conflict of .env files #239

Open
chf007 opened this issue Apr 27, 2022 · 4 comments
Open

Nx and Vite handling conflict of .env files #239

chf007 opened this issue Apr 27, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@chf007
Copy link

chf007 commented Apr 27, 2022

the ideal priority

/apps/[app]/.env.[mode].local
/apps/[app]/.env.[mode]
/apps/[app]/.env.local
/apps/[app]/.env
/.env.[mode].local
/.env.[mode]
/.env.local
/.env

but if there is an environment variable in both above file, the one in [mode] will not take effect

the reason is that Nx will first process /apps/[app]/.env.local /apps/[app]/.env /.env.local /.env,and Nx does not support mode mode,[mode] files will not be processed

when the Vite executor is executed, Vite will process all .env files, but at this time the environment variable Vite pre-processed by Nx will not overwrite

@chf007
Copy link
Author

chf007 commented Apr 28, 2022

https://github.com/chf007/vite-plugin-nx-dotenv

I wrote a plugin for Vite to temporarily solve this problem.

@ZachJW34
Copy link
Owner

Cool fix @chf007! If you want, you can open a PR and add a snippet in the @nx-plus/vite README about this package

@chf007
Copy link
Author

chf007 commented May 6, 2022

There are still some problems with the plugin: because the priority of the plugin cannot be higher than the Vite built-in define plugin, the ideal priority cannot be achieved in the build mode.

At present, it may only be solved by giving pr to Vite.

@chf007
Copy link
Author

chf007 commented May 11, 2022

There are still some problems with the plugin: because the priority of the plugin cannot be higher than the Vite built-in define plugin, the ideal priority cannot be achieved in the build mode.

At present, it may only be solved by giving pr to Vite.

This problem has been solved in vite-plugin-nx-dotenv version 1.0.1, regardless of serve mode or build mode, we can correctly get the desired environment variable value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants