Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SASS loader duplicates CSS styles styles #5057

Closed
Timmmm opened this issue Jan 8, 2020 · 4 comments
Closed

SASS loader duplicates CSS styles styles #5057

Timmmm opened this issue Jan 8, 2020 · 4 comments

Comments

@Timmmm
Copy link

Timmmm commented Jan 8, 2020

Version

4.1.0

Reproduction link

https://github.com/Timmmm/vue_sass_issue.git

Environment info

MacOS 10.14.

Steps to reproduce

  1. Create the a new project with Vue CLI. I used Typescript & node-sass.
  2. Add Element (https://element.eleme.io/)
  3. Customise the style as described here: https://element.eleme.io/#/en-US/component/custom-theme#update-scss-variables-in-your-project
  4. Add an el-input element.

What is expected?

el-input should have one style applied

What is actually happening?

You get approximately 6 copies of the Element styles applied to the el-input element. This shows the first two duplicates but you can scroll down and there are loads more:

image

@Timmmm Timmmm changed the title SASS loader duplicates Element CSS style SASS loader duplicates CSS styles styles Jan 8, 2020
@Timmmm
Copy link
Author

Timmmm commented Jan 8, 2020

Actually this appears to not be an issue with Element. It exposes it because it @imports the same file twice but you can easily do it yourself like this:

// theme.scss
@import "./style_a";
@import "./style_b";
// style_a.scss
.foo {
  color: red;
}
// style_b.scss
@import "./style_a"

You then get two copies of the .foo rule. I think this might be due to this issue in sass-loader which they closed as "we don't know how to fix this". :-/

@LinusBorg
Copy link
Member

Well if you include duplicate styles, you will have duplicate styles.

You can probably config cssnano to remove duplicates during minification I'd it doesn't do that already.

We can't do much about this.

@Timmmm
Copy link
Author

Timmmm commented Jan 9, 2020

Yeah fair enough - this seems to be an inherent flaw in the was Sass works. The Chalk theme people get around it by running the output through cssmin. I guess I will do the same.

@Timmmm Timmmm closed this as completed Jan 9, 2020
@LinusBorg
Copy link
Member

LinusBorg commented Jan 9, 2020

Just to repeat : we already miniy css during build and the cssnano plugin we use should be able to remove duplicate rules as well. I think it actually does by default

Might be worth looking into before you add another tool to the chain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants