No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [V1] A guide for @quasar/dotenv

    Useful Tips (NEW)
    cli dotenv extension v1.0
    9
    14
    3625
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mKomo last edited by mKomo

      Hi all, this is my unofficial guide on how to use the quasar dotenv extension.

      1. Install the quasar app extension:
         $ quasar ext add @quasar/dotenv            
      
      1. Follow the setup instructions, here you’ll specify the names for your production and development .env files ex: dev.env // prod.env

      2. Create files in your root directory based on the names specified in step (2)

         // dev.env              
      
         FOO=bar   
      
      1. You’re all set, you can access these vars in any file via process.env.<var-name>
         // src/components/example.vue         
          
          ...
          mounted() {
            console.log(process.env.FOO)            
          },
          ...
      
      

      For more information check out:

      • Github repo

      Why I wrote the post:

      • This is very similar to the steps in the github repo but it wasn’t immediatley clear that I had to make new files and how the variables I specified would be accessible in my files.

      If anythings missing feel free to correct me below 🙂 / add to the knowledge of how to use this great framework

      1 Reply Last reply Reply Quote 5
      • nothingismagick
        nothingismagick last edited by

        @Hawkeye64 - check this out. Thanks @mKomo

        1 Reply Last reply Reply Quote 0
        • nothingismagick
          nothingismagick last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • nothingismagick
            nothingismagick last edited by

            I just created two issues that should hopefully resolve your concerns.

            https://github.com/quasarframework/app-extension-dotenv/issues/3
            https://github.com/quasarframework/app-extension-dotenv/issues/4

            1 Reply Last reply Reply Quote 0
            • Hawkeye64
              Hawkeye64 last edited by

              @mKomo This is great feedback, thanks!

              M 1 Reply Last reply Reply Quote 0
              • M
                mKomo @Hawkeye64 last edited by

                @Hawkeye64 happy to help! If you need a hand with docs / guides feel free to drop message 🙂

                1 Reply Last reply Reply Quote 0
                • A
                  AndrewE last edited by AndrewE

                  How do you get the prompts?
                  I’ve installed and unistalled and re-installed @quasar/dotenv, but I do not get the prompts to set the env files. I’ve added dev.env and prod.env files manually and put my firebase config in them. However, I get a build error that App Extension “@quasar/dotenv” has missing index script…
                  Is this script created via the prompts? Where would this script be found?
                  When I run “add” it just lists the extension and shows an empty prompts object:
                  $quasar ext add @quasar/dotenv

                  app:extension-manager Listing installed App Extensions +0ms
                  
                  Extension name: @quasar/dotenv
                  Extension prompts: {}
                  

                  update: I got no prompts when trying to run dotenv in a clone of https://github.com/kpapro/quasar-firebase-firestore

                  I did get prompts in my project folder which was init’ed with the recent quasar build (v1.0.0-beta.19).

                  1 Reply Last reply Reply Quote 0
                  • s.molinari
                    s.molinari last edited by

                    @AndrewE - The way it looks in that firebase scaffold, the dotenv app extension is already installed. Theoretically, the author of that repo should be making an app extension themselves to install that scaffold. 😁

                    Scott

                    A 1 Reply Last reply Reply Quote 0
                    • A
                      AndrewE @s.molinari last edited by

                      @s-molinari
                      Thanks for pointing that out!

                      1 Reply Last reply Reply Quote 0
                      • A
                        aeiosapp last edited by

                        Nice solution, by the way it works fine when I call process.env.MYVAR jn the <script> section of my *.vue file, but it doesn’t work when I call it in my src/app/local.js file where I’d like to put some functions that I’ll call in a <script> of *.vue file. Any ideas how to handle it??

                        A 1 Reply Last reply Reply Quote 0
                        • A
                          aeiosapp @aeiosapp last edited by

                          @aeiosapp said in [V1] A guide for @quasar/dotenv:

                          Nice solution, by the way it works fine when I call process.env.MYVAR jn the <script> section of my *.vue file, but it doesn’t work when I call it in my src/app/local.js file where I’d like to put some functions that I’ll call in a <script> of *.vue file. Any ideas how to handle it??

                          Found solution for my question. Just had to add this code in my src/app/local.js file:

                          const DotEnv = require('dotenv')
                          
                          if(parsedEnv = DotEnv.config().parsed) {
                            for (let key in parsedEnv) {
                              process.env[key] = parsedEnv[key]
                            }
                          }
                          
                          
                          A 1 Reply Last reply Reply Quote 0
                          • C
                            Christal last edited by

                            How do you build a copy based on .env.staging

                            1 Reply Last reply Reply Quote 0
                            • A
                              ArkIv @aeiosapp last edited by

                              @aeiosapp
                              quasar.conf.json

                              build:{
                                 env: {...require("./config_env")}
                                ... or
                                 env: {
                                      version: require("./package.json").version,
                                      ...require("./config_env")
                                    },
                               ... or
                                env: {...require("./config_env"), 
                                      ...require("./config_env-2"}
                              

                              ./config_env.js

                              module.exports={
                               title: "no dotenv"
                              }
                              
                              B 1 Reply Last reply Reply Quote 0
                              • B
                                baramofme @ArkIv last edited by

                                @ArkIv That’s good.

                                dotenv not working my quasar. so I mixed your method + qenv.

                                .quasar.env.json

                                {
                                  "development": {
                                    "ENV_TYPE": "Running Development",
                                    "ENV_DEV": "Development",
                                    "API_URL": "https://dev.some.com"
                                  },
                                  "production": {
                                    "ENV_TYPE": "Running Production",
                                    "ENV_PROD": "Production",
                                    "API_URL": "https://some.com"
                                  },
                                  "test": {
                                    "ENV_TYPE": "Running Test",
                                    "ENV_Test": "Test"
                                  },
                                  "stage": {
                                    "ENV_TYPE": "Running Stage",
                                    "ENV_STAGE": "Stage",
                                    "API_URL": "https://stg.some.com"
                                  }
                                }
                                
                                

                                quasar.conf.json

                                const configEnv = require('./.quasar.env.json')
                                
                                module.exports = configure(function (ctx) {
                                  return {
                                    ......
                                          env: {
                                             // for settting proxy address with ctx.dev, ctx.prod
                                             IS_STAGE: false,
                                          },
                                    },
                                
                                    devServer: {
                                      proxy: {
                                        // proxy all requests starting with /api to specific url
                                        '/api': {
                                          target: ctx.prod ? configEnv["production"].API_URL
                                          : process.env.IS_STAGE ? configEnv["stage"].API_URL
                                              : configEnv["development"].API_URL,
                                          changeOrigin: true,
                                          pathRewrite: {
                                            '^/api': ''
                                          }
                                        },
                                 
                                
                                1 Reply Last reply Reply Quote 1
                                • First post
                                  Last post