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

Variables are undefined when build in production with Vitejs #347

Open
jdinartejesus opened this issue Mar 8, 2022 · 1 comment
Open

Comments

@jdinartejesus
Copy link

I'm currently using Vuejs with Vitejs, but when I'm running the build in production, the variables are undefined. Vitejs it's like ReactCreateApp, using the REACT_APP_ prefix, but instead we need to use VITE_ prefix, and even when applying this still doesn't work.

.env-cmdrc.js

module.exports = {
  "development": {
     "VITE_APP_DB_ENV": "development",
     "VITE_APP_BUILD_ENV": "development",
     "VITE_HASURA_ENGINE_URL": "URL"
     ...
  },
  "staging": {
     "VITE_APP_DB_ENV": "staging",
     "VITE_APP_BUILD_ENV": "production",
     "VITE_HASURA_ENGINE_URL": "URL"
     ...
  },
  "production": {
     "VITE_APP_DB_ENV": "production",
     "VITE_APP_BUILD_ENV": "production",
     "VITE_HASURA_ENGINE_URL": "URL"
     ...
  }
}

package.json:

"scripts": {
  "start": "env-cmd -e ${APP_ENV:=production} npm run gql:generate && vite build",
}
@nichita-pasecinic
Copy link

nichita-pasecinic commented Apr 5, 2022

@jdinartejesus did you try to pass just the production for the -e ? or switch with places the npm run gql:generate with vite build ?
I've worked today with the env-cmd and vitejs and did not have any problems. Here is a simple example using both tools

Edit: seems like the env-cmd is setting the env variables for the first command, to run multiple commands see this docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants