Build using environment variables in staging #17191
-
I'm trying to learn, what is the correct way to use environment variables, that changes based on the mode of the app The way I see it, I should have three different modes: development, staging and production At first I thought I would need to edit quasar.config.js to something like this
But as far as I can tell, there's only ctx.dev and ctx.production Then I tried to add the files .env.production, .env.staging and .env where I added VITE_API= with their respective addresses, hoping for some magic here. Unfortunately I have no idea how to build it for staging
Here I run into the same problem. I can only find commands to build in production or development |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I finally managed to find a workaround to get it working I created this file: \variables\parser.js `const dotenv = require('dotenv'); const files = { module.exports = () => In the same folder I created different .env files (e.g. .env.staging) where I added the variables they needed Inside quasar.config.js I added this line to the top: And further down I did this: In package.json I added this line unders scripts:
I found the information in this discussion: #15065 |
Beta Was this translation helpful? Give feedback.
I finally managed to find a workaround to get it working
I created this file: \variables\parser.js
`const dotenv = require('dotenv');
const files = {
...dotenv.config({ path: 'variables/.env' }).parsed,
...dotenv.config({ path:
variables/.env.${process.env.ENVIRONMENT}
}).parsed,...dotenv.config({ path:
variables/.env.${process.env.ENVIRONMENT}.local
}).parsed,};
module.exports = () =>
{
Object.keys(files, (key) =>
{
if (typeof files[key] !== 'string')
{
files[key] = JSON.stringify(files[key]);
}
});
return files;
};
`
In the same folder I created different .env files (e.g. .env.staging) where I added the variables they needed
Inside quasar.config.js I added this line to the top:
const …