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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With