Skip to content

feat(@angular/cli): add fallback for CSS variables #7770

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

Merged
merged 2 commits into from
Sep 25, 2017
Merged

feat(@angular/cli): add fallback for CSS variables #7770

merged 2 commits into from
Sep 25, 2017

Conversation

garoyeri
Copy link
Contributor

Aim to resolve #7514 by including postcss-custom-properties. This will generate extra rules in CSS when a var() is used to allow for compatibility with older IE browsers that do not support the feature.

Add postcss-custom-properties module to provide backwards-compatible support for "var" keyword in CSS files.

Working towards resolving #7514.
Add postcss-custom-properties module the @angular/cli package template. Include postcss-custom-properties in the style pipeline.

Working towards resolving #7514.
Copy link
Contributor

@filipesilva filipesilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think this is a good fix. Thanks!

@filipesilva filipesilva merged commit 29ec3c0 into angular:master Sep 25, 2017
@garoyeri garoyeri deleted the fix-7514-round2-master branch September 25, 2017 15:22
filipesilva pushed a commit that referenced this pull request Sep 28, 2017
Aim to resolve #7514 by including postcss-custom-properties. This will generate extra rules in CSS when a `var()` is used to allow for compatibility with older IE browsers that do not support the feature.
@cyrilletuzi
Copy link
Contributor

@garoyeri Is this supposed to work everywhere in the app ? Because currently it seems to work for CSS variables declared and used in the global styles (src/styles.scss) but not for CSS variables used in components' styles.

@garoyeri
Copy link
Contributor Author

garoyeri commented Dec 1, 2017

Reading through https://github.com/postcss/postcss-custom-properties/blob/master/README.md, there are some caveats on what works and what doesn't. Primarily, it will only work on variables declared in the :root selector. This was a trade-off that I was okay with since I was using it to handle theming use cases.

@cyrilletuzi
Copy link
Contributor

@garoyeri Yes my variables are in :root, but they are only transformed for styles using them in style.scss but not in styles of components.

@garoyeri
Copy link
Contributor Author

garoyeri commented Dec 1, 2017

Ok, I did a little more digging, turns out that it is completely unsupported by postcss-custom-properties as per the issue here: postcss/postcss-custom-properties#68.

Basically, the plugin only operates on a single file unless you use postcss-import to inline the other styles which may cause weird things to happen. The only thing I can think of off the top of my head is to create a theme stylesheet globally that will be used by the component to map your theme variables onto the specific styles you want to override. This definitely isn't ideal, and supporting IE11 is an uphill journey :(

dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this pull request Apr 23, 2018
Aim to resolve angular#7514 by including postcss-custom-properties. This will generate extra rules in CSS when a `var()` is used to allow for compatibility with older IE browsers that do not support the feature.
@nicky-lenaers
Copy link

@cyrilletuzi I'm stubling upon the same issue where component styles are not using the values generated by postcss-custom-properties. Do you have a workaround for this?

@cyrilletuzi
Copy link
Contributor

cyrilletuzi commented Aug 21, 2018

@nicky-lenaers This feature has been removed from the CLI, because the issue couldn't be solved.

@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 12, 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

Successfully merging this pull request may close these issues.

add fallback for css variables
5 participants