0

I've migrated vue app to nx, all is fine now except of one thing - previously, .env file was used in both dev and production environments, during development as well as build, vue-cli-service took care of that. Now I struggle with app build - it doesn't seem to read .env file, or I just do it wrong.

I've tried to add dotenv-webpack and add it in the configure-webpack.js but during build none of the variables was accessible. Here is the file example:

//.env
SOME_API_URL=$API_URL

// config.ts
export const CONFIG = {
  api_url = process.env.SOME_API_URL
}
// during build process.env is undefined

build command looks like this:

export API_URL='http://vue-app.com'; nx build frontend --skip-nx-cache
akkonrad
  • 1,043
  • 1
  • 10
  • 25

1 Answers1

0

You would need to switch to Vite but we’ve had good success using this plugin for our applications: https://github.com/chf007/vite-plugin-nx-dotenv

Shafiq Jetha
  • 1,337
  • 16
  • 30