Can we get props from quasar.config.js? (0.15)
-
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.htmlI 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')
-
If you want to set custom config either use env variables or build a custom config object.
-
@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?
-
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.
-
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.jsAny 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. -
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 thatvm.$options.*
is not reactive). -
@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 }
-
@a47ae In this case, I’m not sure if
this.$config
would be reactive (what means creating extra listeners) or not. -
@leopiccionia No it would not be reactive.
But in this case, it wouldn’t matter because you certainly would not edit thequasar.conf.js
during runtime -
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