Description
Didn't find a word about this on the documentation, so I can't resolve this issue by myself.
So I started my project with vue-cli using vue init webpack projectname
, and started fiddling around. As far as I understand, the app starting point is src/App.vue, which wraps components together.
So the style-block there is the "global" styles, that I can use to create "universal" styles available in every component, as it isn't scoped, but I'm having an issue with variables. The variables I create aren't available in other templates:
App.vue:
<style lang="stylus">
@import 'jeet'
colors = {
gray: #222,
red: rgb(255, 0, 0)
}
body{
background: colors.gray // works fine
}
</style>
components/Navigation.vue:
<style scoped lang="stylus">
// the scoped attribute doesn't make a difference, the variable doesn't work.
header{
background: colors.gray
}
</style>
See where I'm going here? It's probably an error on my part, but how am I supposed to create variables that are available in every template?
The same goes for plugins such as jeet. I think I can deal with it if I have to @import 'jeet'
in every style block, but I'd rather not if I don't have to. The traditional way that I used to do looks like this:
app.styl:
@import 'jeet'
colors = {
gray: #222
red: rgb(255, 0, 0)
}
@import 'header'
@import 'article'
...
So I kinda expected it to work a bit like this. Obviously it doesn't, but as I said, I didn't find a word about this in the documentation. Might be worth mentioning that this is the first time I'm using webpack, as I was happy with rollup and npm scripts.
**E:**I stumbled upon this (http://vuejs-templates.github.io/webpack/pre-processors.html#standalone-css-files) but it wasn't what I'm looking for. The global styles work just fine in it, but even if I define my variables (or stylus hashes) or @import 'jeet'
, the build fails if I try to use them inside templates.
I got a suggestion to use separate file for variables and @import them in each template. Sounds okay to me as a workaround, but I'd still like to know if there's an actual way of doing what I want to do.