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

    Can we get props from quasar.config.js? (0.15)

    Framework
    5
    10
    2775
    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.
    • D
      dgk last edited by

      Didn’t see anything in the docs but I assume there is a method (similar to express app) for getting any value of a property from within a .vue object?
      http://quasar-framework.org/guide/app-quasar.conf.js.html

      I want to set some of my own custom properties/keys in quasar.config.js and then be able to grab them.

      something like this I imagine
      this.$q.configGet('propname')

      1 Reply Last reply Reply Quote 1
      • a47ae
        a47ae last edited by

        If you want to set custom config either use env variables or build a custom config object.

        flachica 1 Reply Last reply Reply Quote 0
        • flachica
          flachica @a47ae last edited by

          @a47ae This is a solution, but I think it is not the best solution. In this way we would have two configuration files. Is there any way to read the properties of the quasar.conf.js file?

          1 Reply Last reply Reply Quote 0
          • D
            dgk last edited by

            For end user configs @a47ae 's suggestion is fine. A second config file maybe in cson or yaml to make it easy for end users is best. That’s not needed as part of quasar. Env variables would be fine for cases where just one or two things need to be set by end user. But for custom “built in” settings for the quasar app itself (not for end users) being able to set and grab them from quasar.conf would be nice.

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

              The problem is that quasar.conf.js requires a context that is passed.
              Here is the source from quasar-cli which parses the config: https://github.com/quasarframework/quasar-cli/blob/dev/lib/quasar-config.js

              Any special settings you wanted to read from that config file?
              You could go the other way and import your custom config file (e.g. /src/config/index.js) in Quasars config file.

              1 Reply Last reply Reply Quote 0
              • L
                leopiccionia last edited by

                I think that a more Vue-centric solution would be registering a Vue mixin, either globally (you may need an app plugin for it) or locally.

                Example (global):

                Vue.mixin({
                    foo: {
                        bar: 'baz'
                    }
                })
                

                Then access it as this.$options.foo.bar (please notice that vm.$options.* is not reactive).

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

                  @leopiccionia You don’t need a mixin for this.

                  Assuming you had access to the config (which is not easily possible because it is a function which requires a context), you could have an app plugin like this:

                  import config from 'quasar.conf.js' // This does not work
                  
                  export default ({ Vue }) => {
                    Vue.prototype.$config= config
                  }
                  
                  L 1 Reply Last reply Reply Quote 0
                  • L
                    leopiccionia @a47ae last edited by

                    @a47ae In this case, I’m not sure if this.$config would be reactive (what means creating extra listeners) or not.

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

                      @leopiccionia No it would not be reactive. 🙂
                      But in this case, it wouldn’t matter because you certainly would not edit the quasar.conf.js during runtime 😃

                      1 Reply Last reply Reply Quote 0
                      • M
                        mohamadJ last edited by

                        you can use let ctx = require(‘path/quasar.conf.js’) for import conf file in your js files.then use ctx().foo for access foo in quasar.conf.js

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post