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

mixin to generate font-face and .material-icons #83

Comments

@jaschwartzkopf
Copy link

I'm working on an angular library project that is adding support for @use.

We'd like to be able to control when/where/if CSS is generated. To do that it would be nice if there was a mixin that wrapped the SCSS in material-design-icons.scss so we could @use _mixins.scss and not generate any CSS until/unless we call the mixin.

The reason we want this is we don't want angular components accidentally regenerating the font face, etc. every time they @use our library. With the way the angular cli handles rewriting asset paths, it's hard to get the path right if we just try to generate the font-face ourselves.

@jossef
Copy link
Owner

jossef commented Feb 19, 2022

best I can think of is adding a @main mixing to the _mixings.scss file
and the material-design-icons.scss will invoke it.
on the other hand, you can simply use the mixing directly from the _mixins.scss file.

WDYT?

@jaschwartzkopf
Copy link
Author

The main problem we had was with the font-face, since the way the Angular CLI re-writes CSS urls makes it hard for us to write it ourselves (but works when it comes from you SCSS, something to do with were the files are relative to the SCSS file). Currently the @font-face is not in a mixin (neither is the .material-icons class).

A @main mixin would work for us.

@clshortfuse
Copy link

clshortfuse commented Mar 16, 2022

Sass itself provides no code-splitting options and it's not part of any of their goals:

https://github.com/sass/sass/blob/main/accepted/module-system.md#non-goals

Despite many libraries exporting top-level rules like this one, it's not suggested by the Sass developer:

sass/sass#2875 (comment)

The take here is for the default material-design-icons.scss file to just import from others:

@include mixins.fontFaceMixin();
.material-icons {
  @include mixins.classRulesMixin();
}

Then custom implementations can pick and choose how often they load where as the default implementation stays top-level as expected. But as the sass dev comment says, it can be brittle if you don't have an API strategy (ie: want to change _mixins.scss).

@jossef jossef closed this as completed in 91be92a Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment