Topic: Using .env / VUE_APP environment variables
Mike Barlow asked 5 years ago
Trying to make use of environment variables in my MDBootstrap app.
I've read that I should be able to add environment variables in my .env
file in the root of my project (I've put it in the root
, in the src/assets
, config
) and that any variable starting with VUE_APP
should be available in vue by using process.env.VUE_APPXXX
with no success.
How does MDBootstrap vue work with environment variables?
Thanks
Gary Woodfine pro answered 5 years ago
@Mike Barlow , I wrote a blog post which should help a little https://garywoodfine.com/using-environment-variables-in-vue-js/
Mike Barlow commented 5 years ago
Thanks @Gary Woodfine, much appreciated. Actually yours was one of the articles I read on the subject before trying here. My problem was where to put the .env.js file so it could be pulled in by webpack
Mikołaj Smoleński staff answered 5 years ago
Unfortunately I can't help with Vue, because we don't use environment variables in our library.
In the other webpack base projects it looks like this:
cross-env NODE_ENV=production --env.<your-variable>=true webpack --config webpack/webpack.config.prod.js --colors
Best regards
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: MDB Vue
- MDB Version: 5.8.3
- Device: Any
- Browser: Any
- OS: windows
- Provided sample code: No
- Provided link: No
Mike Barlow commented 5 years ago
Ok, just found one solution (is this the prefered one?) In my
config\dev.env.js
file I added:VUE_APP_API_BASE: '"http://localhost:8084/"'
and that appears to work