[How To] Import Stylus variables depending on the current theme
-
Recently @benoitranque asked on Gitter how to import not the
quasar.variables.styl
file in a component (which is easy, just write@import '~variables'
), but theapp.<THEME>.styl
variables.After tinkering a bit with the webpack alias config I finally figured it out.
You have to replace the existingvariables
alias with the following line:variables: path.resolve(__dirname, '../src/themes/app.' + env.platform.theme + '.styl')
. But because the alias are all configured inconfig/index.js
and somehow there is an issue with reading theenv
variable in this file (would be glad if someone can point out why), you need take the alias definitions and write them directly in thebuild/webpack.base.conf.js
file.The last thing to notice is that if you import that file, as far as I know, you also copy all the Quasar styles into your component again, really bloating up the styles. So you would propably be better of by creating two new files
mat.variables.styl
andios.variables.stly
which you import in the correspondingapp.<THEME>.styl
files right before Quasar is imported and then change the alias definition tovariables: path.resolve(__dirname, '../src/themes/' + env.platform.theme + 'variables.styl')