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

Duplicate import problem with sass #110

Closed
sdvcrx opened this issue Dec 23, 2015 · 3 comments
Closed

Duplicate import problem with sass #110

sdvcrx opened this issue Dec 23, 2015 · 3 comments

Comments

@sdvcrx
Copy link

sdvcrx commented Dec 23, 2015

Hi! Thank you for the amazing vuejs!

I trying to use sass with vue, but I encountered some problems here.

For example, I have a sass file named common.sass which almost every vue files need it, so I import it on *.vue:

// app.vue, other.vue ...
<style lang="sass">
@import "common";
// ....
</style>

Then common.sass will be imported many times, which make the compiled css file very large because it has many duplicate code.

Is there a better way to do it? Thanks again!

@yyx990803
Copy link
Member

That's just how it works - in general, you should only put abstract stuff like variables and mixins in shared imports.

Also, if you use the extract css setup for production build, the final CSS will be processed with cssnano which will remove all duplicate rules.

@chenxeed
Copy link

chenxeed commented May 2, 2018

Not sure if it'll works for everyone,

we have same problem like this that needs to be solved, the difference is the CSS comes from a plugin library, in this case handsontable.

We have two Vue component that uses this library, and we prefer to have all the component needs (HTML, JS, CSS) are wrapped together in the component.

The problem is that both component basically needs handsontable.css, and we don't want to have this CSS duplicated if we use both component in the same page.

Our workaround is to import the CSS with separated <style> tag, instead of import it.

Below are the example:

(Duplicated)

<style lang="scss">
@import `~handsontable.css`;

// our component stylesheets
</style>

(Not duplicated!)

<style src="handsontable.css" />
<style lang="scss">
// our component stylesheets
</style>

@eomis
Copy link

eomis commented May 10, 2021

@yyx990803

Sorry for disturb. But in this case, if add scoped attribute to style tag, all the imported scss gets scoped as well which leads to massive code duplication for my extracted css.

And I found someone has the same trouble as me:
duplicate global style with scoped

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

4 participants