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.










share|improve this question
























  • 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















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.










share|improve this question
























  • 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













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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]