How to use deploy specific .env in Vuejs
up vote
0
down vote
favorite
I have several environments that I build my Vuejs application to. Each of those environments has a different API that I'd like to call.
My ideal scenario is that I have an .env file in the root of each of the servers I deploy to, so that when I deploy my build, the Vue app looks at the .env that is in it's environment specific location and pulls the relevant API path variables from inside of it.
This way, I can build the app once, and have it deployed on multiple servers and I don't need to make a specific build for each server.
I've tried using dotenv-webpack but it seems that the .env that's included in the build is just from whatever the value is when I create the build, and not fetched from any .env on the individual servers.
I've found that I can use axios to GET a js file from /static but this doesn't really seem like the cleanest approach.
vue.js webpack deployment environment-variables
add a comment |
up vote
0
down vote
favorite
I have several environments that I build my Vuejs application to. Each of those environments has a different API that I'd like to call.
My ideal scenario is that I have an .env file in the root of each of the servers I deploy to, so that when I deploy my build, the Vue app looks at the .env that is in it's environment specific location and pulls the relevant API path variables from inside of it.
This way, I can build the app once, and have it deployed on multiple servers and I don't need to make a specific build for each server.
I've tried using dotenv-webpack but it seems that the .env that's included in the build is just from whatever the value is when I create the build, and not fetched from any .env on the individual servers.
I've found that I can use axios to GET a js file from /static but this doesn't really seem like the cleanest approach.
vue.js webpack deployment environment-variables
Have you looked at the npm 'config' package? It picks up config based on your NODE_ENV environement variable. npmjs.com/package/config
– Jim B.
2 days ago
1
I think this article addresses what you are asking about: alligator.io/vuejs/working-with-environment-variables
– Jayem163
2 days ago
@Jayem163 Looks like this pulls those env variables into the build, therefore, for each environment I'm deploying to (more than 5), I'd need to create a new build for each. What I want is 1 build, that can deploy to all my different servers and they have their own env that they can grab those variables from.
– justinl
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have several environments that I build my Vuejs application to. Each of those environments has a different API that I'd like to call.
My ideal scenario is that I have an .env file in the root of each of the servers I deploy to, so that when I deploy my build, the Vue app looks at the .env that is in it's environment specific location and pulls the relevant API path variables from inside of it.
This way, I can build the app once, and have it deployed on multiple servers and I don't need to make a specific build for each server.
I've tried using dotenv-webpack but it seems that the .env that's included in the build is just from whatever the value is when I create the build, and not fetched from any .env on the individual servers.
I've found that I can use axios to GET a js file from /static but this doesn't really seem like the cleanest approach.
vue.js webpack deployment environment-variables
I have several environments that I build my Vuejs application to. Each of those environments has a different API that I'd like to call.
My ideal scenario is that I have an .env file in the root of each of the servers I deploy to, so that when I deploy my build, the Vue app looks at the .env that is in it's environment specific location and pulls the relevant API path variables from inside of it.
This way, I can build the app once, and have it deployed on multiple servers and I don't need to make a specific build for each server.
I've tried using dotenv-webpack but it seems that the .env that's included in the build is just from whatever the value is when I create the build, and not fetched from any .env on the individual servers.
I've found that I can use axios to GET a js file from /static but this doesn't really seem like the cleanest approach.
vue.js webpack deployment environment-variables
vue.js webpack deployment environment-variables
edited 2 days ago
asked 2 days ago
justinl
5,086186185
5,086186185
Have you looked at the npm 'config' package? It picks up config based on your NODE_ENV environement variable. npmjs.com/package/config
– Jim B.
2 days ago
1
I think this article addresses what you are asking about: alligator.io/vuejs/working-with-environment-variables
– Jayem163
2 days ago
@Jayem163 Looks like this pulls those env variables into the build, therefore, for each environment I'm deploying to (more than 5), I'd need to create a new build for each. What I want is 1 build, that can deploy to all my different servers and they have their own env that they can grab those variables from.
– justinl
2 days ago
add a comment |
Have you looked at the npm 'config' package? It picks up config based on your NODE_ENV environement variable. npmjs.com/package/config
– Jim B.
2 days ago
1
I think this article addresses what you are asking about: alligator.io/vuejs/working-with-environment-variables
– Jayem163
2 days ago
@Jayem163 Looks like this pulls those env variables into the build, therefore, for each environment I'm deploying to (more than 5), I'd need to create a new build for each. What I want is 1 build, that can deploy to all my different servers and they have their own env that they can grab those variables from.
– justinl
2 days ago
Have you looked at the npm 'config' package? It picks up config based on your NODE_ENV environement variable. npmjs.com/package/config
– Jim B.
2 days ago
Have you looked at the npm 'config' package? It picks up config based on your NODE_ENV environement variable. npmjs.com/package/config
– Jim B.
2 days ago
1
1
I think this article addresses what you are asking about: alligator.io/vuejs/working-with-environment-variables
– Jayem163
2 days ago
I think this article addresses what you are asking about: alligator.io/vuejs/working-with-environment-variables
– Jayem163
2 days ago
@Jayem163 Looks like this pulls those env variables into the build, therefore, for each environment I'm deploying to (more than 5), I'd need to create a new build for each. What I want is 1 build, that can deploy to all my different servers and they have their own env that they can grab those variables from.
– justinl
2 days ago
@Jayem163 Looks like this pulls those env variables into the build, therefore, for each environment I'm deploying to (more than 5), I'd need to create a new build for each. What I want is 1 build, that can deploy to all my different servers and they have their own env that they can grab those variables from.
– justinl
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343305%2fhow-to-use-deploy-specific-env-in-vuejs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you looked at the npm 'config' package? It picks up config based on your NODE_ENV environement variable. npmjs.com/package/config
– Jim B.
2 days ago
1
I think this article addresses what you are asking about: alligator.io/vuejs/working-with-environment-variables
– Jayem163
2 days ago
@Jayem163 Looks like this pulls those env variables into the build, therefore, for each environment I'm deploying to (more than 5), I'd need to create a new build for each. What I want is 1 build, that can deploy to all my different servers and they have their own env that they can grab those variables from.
– justinl
2 days ago