I have seen many other questions on this topic, but none have helped me.
With vue I want to use an api, but the url will change when the app is in production so in the .env file I have defined a BASE_URL, but when I use it in a vue component, it says that procces is not defined.
I've tried with webpack.DefinePlugin in webpack.config.js or naming the environment variables as VUE_APP_BASE_URL but nothing seems to work.
export default {
name: "Dashboard",
data() {
return {
data: undefined
}
},
created() {
axios
.get(process.env.BASE_URL + "/api/xxxxx")
.then(res => this.data = res.data)
},
};
webpack.config.js:
plugins: [
new VueLoaderPlugin(),
new webpack.DefinePlugin({
'process.env.BASE_URL': JSON.stringify(process.env.BASE_URL),
})
]
.env:
BASE_URL=http://localhost:3000/
webpack version: 5.48.0
