Skip to content

Sass file import in every component creating duplicate copies of sass file data on run time #8431

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

Closed
amareshteja opened this issue Nov 10, 2017 · 3 comments

Comments

@amareshteja
Copy link

amareshteja commented Nov 10, 2017

I'm trying to use Sass with angular 4. like this,
@import "~assets/css/svg-icons";

Everything works fine. But the problem is, I've to import same sass file in every component individually (In both parent and child components).
So on compile time angular-cli injecting complete content of svg-icons.scss file, in every component with some attribute appended to all the classes of that file, like .view-icon[_ngcontent-c1], .view-icon[_ngcontent-c2].

So, If there is 100 lines of code in svg-icons.scss, and If I import it in 10 components, It'll be 1000 lines of duplicated code, which will be injected to index.html, on run time. I don't want this duplication of code as this increases the size of the file exponentially. How can I resolve this?

@Ristaaf
Copy link

Ristaaf commented Nov 10, 2017

This is basic sass behaviour, you should never import things that result in css several times (sass files imported into component should typically only contain variables, mixins and functions). If you need your import to happen only once, add it to the styles part of .angular-cli.json. (btw the attribute part of the css rules are from having your angular components encapsulated (on by default) this is to make sure that your css in a component does not apply to anything outside your component).

@david-bulte
Copy link

david-bulte commented Apr 16, 2019

But if you need something from another scss file in the component.scss file, how would you accomplish this without an import? Eg. you need the '$primary' variable (bootstrap user here). You could of course put all your styles in the global styles.scss file, but then you loose the advantage of keeping the styles local to the component. Couldn't the cli provide some help here?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants