Skip to content

Commit 2a78378

Browse files
committed
feat(@quasar/app): Auto-inject Quasar stylus variables to any .styl file (no longer needed to add import quasar-variables)
1 parent b28ab4a commit 2a78378

38 files changed

+425
-455
lines changed

app/lib/webpack/create-chain.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ module.exports = function (cfg, configName) {
5454
pages: appPaths.resolve.src(`pages`),
5555
assets: appPaths.resolve.src(`assets`),
5656
boot: appPaths.resolve.src(`boot`),
57+
58+
// TODO: remove in final v1.0
59+
// (no longer needed; automatically injects Stylus variables)
5760
'quasar-variables': appPaths.resolve.app(`.quasar/app.quasar-variables.styl`),
5861

5962
// CLI/App using this one:

app/lib/webpack/inject.style-rules.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const
44
appPaths = require('../app-paths'),
55
postCssConfig = require(appPaths.resolve.app('.postcssrc.js'))
66

7-
function injectRule (chain, pref, lang, test, loader, options) {
7+
function injectRule (chain, pref, lang, test, loader, loaderOptions) {
88
const baseRule = chain.module.rule(lang).test(test)
99

1010
// rules for <style lang="module">
@@ -37,7 +37,7 @@ function injectRule (chain, pref, lang, test, loader, options) {
3737
1 + // stylePostLoader injected by vue-loader
3838
1 + // postCSS loader
3939
(!pref.extract && pref.minify ? 1 : 0) + // postCSS with cssnano
40-
(loader ? 1 : 0),
40+
(loader ? (loader === 'stylus-loader' ? 2 : 1) : 0),
4141
sourceMap: pref.sourceMap
4242
}
4343

@@ -86,8 +86,19 @@ function injectRule (chain, pref, lang, test, loader, options) {
8686
.loader(loader)
8787
.options(Object.assign(
8888
{ sourceMap: pref.sourceMap },
89-
options
89+
loaderOptions
9090
))
91+
92+
if (loader === 'stylus-loader') {
93+
// inject Stylus variables automatically
94+
rule.use('style-resources-loader')
95+
.loader('style-resources-loader')
96+
.options({
97+
patterns: [
98+
appPaths.resolve.app(`.quasar/app.quasar-variables.styl`)
99+
]
100+
})
101+
}
91102
}
92103
}
93104
}

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"register-service-worker": "1.6.2",
8282
"semver": "5.6.0",
8383
"strip-ansi": "=3.0.1",
84+
"style-resources-loader": "1.2.1",
8485
"stylus": "0.54.5",
8586
"stylus-loader": "3.0.2",
8687
"terser-webpack-plugin": "1.2.3",

app/templates/app/app.quasar-variables.styl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// NOTICE that you need lang="styl"
1313
//
1414
// <style lang="styl">
15-
// @import '~quasar-variables'
1615
// ........
1716
// </style>
1817

app/yarn.lock

Lines changed: 373 additions & 360 deletions
Large diffs are not rendered by default.

docs/src/components/ApiRows.styl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import '~quasar-variables'
2-
31
.api-row
42
padding 8px 16px 4px
53
font-weight 300

docs/src/components/AppMenu.styl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import '~quasar-variables'
2-
31
.app-menu
42

53
.q-item__section--avatar

docs/src/components/CardTitle.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export default {
2727
</script>
2828

2929
<style lang="stylus">
30-
@import '~quasar-variables'
31-
3230
$title-color = $grey-4
3331
3432
.doc-card-title

docs/src/components/DocExample.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ export default {
150150
</script>
151151

152152
<style lang="stylus">
153-
@import '~quasar-variables'
154-
155153
.doc-example
156154
&__toolbar
157155
background white

docs/src/components/DocLink.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ export default {
3232
</script>
3333

3434
<style lang="stylus">
35-
@import '~quasar-variables'
36-
3735
.doc-link
3836
color $primary
3937
font-weight 500

0 commit comments

Comments
 (0)