Vue.js Package nuxt app in different environment

Vue.js Package nuxt app in different environment,vue.js,vuejs2,nuxt.js,Vue.js,Vuejs2,Nuxt.js,I would like to run npm run generate with environment for example: package.json "scripts": { "staging": "NODE_ENV=staging nuxt generate" } Generate a dist/ with staging environment using npm run staging then when requesting to an API I would like to determine what URL I'm going to use depends on the the environment I'm running let baseURL = () => { switch (process.env.NODE_ENV) { case "it": return "https://example-url.com/it"; case "staging": return "https:

I would like to run

npm run generate
with environment

for example:

package.json

"scripts": {
    "staging": "NODE_ENV=staging nuxt generate"
}

Generate a

dist/
with staging environment using

npm run staging

then when requesting to an API I would like to determine what URL I'm going to use depends on the the environment I'm running

let baseURL = () => {
  switch (process.env.NODE_ENV) {
    case "it":
      return "https://example-url.com/it";
    case "staging":
      return "https://example-url.com/staging";
  }
};

const axiosClient = axios.create({
  baseURL: baseURL(),
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
    "X-Api-Key": state().token
  }
});

the

baseURL()
should return the staging since I packaged the app in staging env


#1

When deploying my app to s3. I would like to deploy the code with environment attached so that the app knows which URL to call. I managed to do this by adding this in package.json

    "generate": "NUXT_ENV_STAGE=it nuxt generate",

According to this https://nuxtjs.org/api/configuration-env/#automatic-injection-of-environment-variables


#2

so what the problem with your code? Keep in mind that env variables are set build time