Nx and Vite handling conflict of .env files
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
https://github.com/chf007/vite-plugin-nx-dotenv
I wrote a plugin for Vite to temporarily solve this problem.
Cool fix @chf007! If you want, you can open a PR and add a snippet in the @nx-plus/vite README about this package
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.
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
buildmode.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.