-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Comments
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). |
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? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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 toindex.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?The text was updated successfully, but these errors were encountered: