Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I avoid duplicate styles with Vue.js components?

I'm new to Vue (and the concept of single file components) and not sure how the CSS is compiled when my app is generated.

I have a pattern library where all the SCSS is compiled for my project so I want to pull this into my components. I know I can load in the mixins and variables globally, then I intend on handpicking other blocks of sass if they need to be used to style that component.

What I'm worried about is:

if I keep using the same style definitions in multiple components, will these be duplicated in the compiled css?

If so. how can that be avoided? Eg: I import the 'headings.scss' in 10 components. Will there be 10 instances of that 'headings.scss' file in the compiled CSS?

I hope that makes sense! Just need some more clarity here.

like image 242
Dom Huxley Avatar asked Dec 12 '17 11:12

Dom Huxley


1 Answers

Yup there will be duplication. But if you are using vuejs webpack template the production build's css is processed by cssnano which will discard duplicated css

note; only exact duplicates will be discarded.

like image 52
Vamsi Krishna Avatar answered Oct 19 '22 08:10

Vamsi Krishna