Describe the bug
In @quasar/app v1, I used to be able to modify the build.env variables from the beforeDev hook, in order to use them after using process.env.MY_VARIABLE
beforeDev({ quasarConf }) {
quasarConf.build.env.TEST = 'HELLO'
}
However, this is not working since v2. When I access process.env.TEST from client code, it is always undefined.
As a note, it is indeed working when specifying the value in build.env directly (not using the hook). However, I am using the hook because I am retrieving a value from an external source, which requires some async calls.
Codepen/jsFiddle/Codesandbox (required)
Fork a Codepen (https://codepen.quasar.dev) or a jsFiddle (https://jsfiddle.quasar.dev) or a Codesandbox (https://codesandbox.quasar.dev) and hit save then copy-paste link here.
https://codesandbox.io/s/bold-sutherland-tytlx?file=/quasar.conf.js
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The value should be defined
Screenshots
If applicable, add screenshots to help explain your problem.
Platform (please complete the following information):
OS:
Node:
NPM:
Yarn:
Browsers:
iOS:
Android:
Electron:
Additional context
Add any other context about the problem here.
Hi,
beforeDev() and beforeBuild() are not meant to be used to modify the quasar config. Please consider it "immutable". The "quasarConf" param is only for informative purposes so devs can take decisions. When it comes to dev mode, it's incorrect to change quasarConf from beforeDev() because that runs only once... any changes to quasar.conf.js file while the dev server is running will recompute the quasarConf but will NOT (and should NOT) run the beforeDev() hook again... since beforeDev()'s main purpose is to inform the dev that the dev server has started (so other services can be called, for example).
However, I understand your concern. And have worked on adding the ability of quasar.conf.js default exported function to be async too. This way you can do your async work then return the configuration inside of the function. This is currently in testing and will be available shortly in "@quasar/app" v2.1.0.
Sounds good, thanks!
The async default exported function will be available in "@quasar/app" v2.1.
Most helpful comment
Hi,
beforeDev() and beforeBuild() are not meant to be used to modify the quasar config. Please consider it "immutable". The "quasarConf" param is only for informative purposes so devs can take decisions. When it comes to dev mode, it's incorrect to change quasarConf from beforeDev() because that runs only once... any changes to quasar.conf.js file while the dev server is running will recompute the quasarConf but will NOT (and should NOT) run the beforeDev() hook again... since beforeDev()'s main purpose is to inform the dev that the dev server has started (so other services can be called, for example).
However, I understand your concern. And have worked on adding the ability of quasar.conf.js default exported function to be async too. This way you can do your async work then return the configuration inside of the function. This is currently in testing and will be available shortly in "@quasar/app" v2.1.0.