-
Notifications
You must be signed in to change notification settings - Fork 227
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
MDC Web is based on Sass, yet Sass is not well supported in React tools #109
Comments
@moog16 Would it be possible to prefix the sass import path of external dependencies with a tilde |
@jimbojetlag How would adding the RE MDC React Guide: |
I was also going to suggest using a different boilerplate other than CRA. There are a lot of Webpack/Sass lovers out there that have created these seed projects. It may not be as heavily supported as CRA (and not Facebook approved), but I'm sure there are some pretty solid ones. I was going to explore other options and link them in MDC React's docs. How does that sound? |
@moog16 You are right about Sass dependencies as demonstrated in the below: Currently with CRA 2.0, importing an MDC React Sass module like this:
, gives this error:
If we add
, then the error gets propagated to the dependency, in this case an MDC Web module:
I cannot see a way for MDC React to stop this error propagation.
The guide is based on CRA 1.x, I was trying to get MDC React work with CRA 2.x, which claims to support Sass and sooner or later will replace the current version, making the guide obsolete. I understand that CRA 2.x is still in alpha.
The difference between CRA and other boilerplates, apart from being official, is that CRA is not a boilerplate. Boilerplates are like ejected CRA, that is you as the developer will inherit the future maintenance burden of the build tools. Depending on the project size, this maintenance may not be trivial. I think the getting stared guide should continue to be based on CRA, but we need to push CRA to have Sass support for dependencies. Like I explained at the beginning of this issue, Sass is not a first class styling tool in React and it community, yet it is the case for MDC. This may cause MDC React having a hard time. |
I agree integrating Sass with CRA has been a big hurdle for us to overcome, but we've been able to get it working between the catalog and using the getting started guide. I think its too early to be looking at CRA 2.0 since its only in alpha. As you know, a lot can change while in alpha. I do see that CRA is stating that they will support Sass compilation, but to what extent and how exactly it'll be enabled is still up in the air. +1 to being different from other boilerplates as it removes "webpack hell" and maintenance. |
Noting that following the getting started guide on Windows 10 leads to this sass issue as described here. I've seen half a dozen solutions, but for someone that's not an expert at webpack configurations - it only leads to confusion. Going try out https://github.com/jamesmfriedman/rmwc to see if that gets me where I want to be.
|
@mswezey23 I just tried CRA with @material/react-button on windows 10 and it worked fine. Let me know what issues you're running into and I can help :) |
I appreciate the amount of work and technological decisions that have gone into the existing Sass styles for Material Components Web and this project, but I agree with @jimbojetlag and I'd really like to be able to customize its styles without Sass before switching from other frameworks. As far as Sass goes, in my opinion it's better to replace it with more modern CSS preprocessors like PostCSS or CSS in JS solutions like styled components for all practical purposes (especially if you're using a dynamic frontend view framework like React). I understand that MDC may have a hard requirement on using Sass for design purposes, but I think we can drop the requirement of end users compiling and writing Sass without impacting the architecture and workflow of the existing styles, allowing users more of a choice in tooling and interop with existing React styling approaches. For example, Bootstrap 4 is written in Sass and provides CSS custom properties for customization without a build tool, which I think is the simplest and most flexible solution as long as your environment supports CSS custom properties. |
I am a fan of CSS in JS and PostCss. We do have PostCSS in our build process, and am not sure how we could use PostCSS to make things easier for the end developer. I haven't used much CSS in JS in projects. How would something like that look like? And how would you go about selecting a framework. Just based off of this list there are a ton of libraries out there. Would you be willing to do a little bit of code in one of the components to show us? |
Personally if I maintained a project in Sass and I didn't need dynamic styles, I would port it to modern CSS (mainly custom properties), optionally using postcss if necessary for legacy browser support. I understand the team may want to continue using Sass, but you can still create CSS custom properties in Sass so they can be changed by end users that don't use Sass (see Bootstrap 4). Then a plain old CSS build can be distributed with the package, which would solve the issue of this not working with CRA without having to wait for v2 to stabilize. I'm pretty new to CSS in JS to be honest, but I don't think it would be possible to use it in core unless you want to completely rewrite and rearchitect all styles in MCW and MCWR. That being said, Styled Components looks like the strongest option to me, but it only works with React. Emotion has a very similar syntax that's almost completely compatible with Styled Components, but it works in any JS framework. Both support writing Sass, but I would still prefer writing CSS custom properties if I were using a CSS in JS library. Ultimately I think just adding CSS custom properties to Sass is the best approach, since they can be set in CSS, CSS modules, Sass, Less, CSS in JS, etc. As far as prior art goes, it's worth mentioning that Material UI used to use inline styles and decided to replace it with JSS after running into scaling and flexibility issues, but I don't like either approach compared to Styled Components or plain CSS personally. |
We already use CSS custom properties in a few of MDC Web's packages. However, they are not a silver bullet. Here are a few problems we've already encountered in MDC Web:
Also, tangentially, I'm not really sure what warrants the insinuation that Sass isn't modern. It's being actively worked on full-time. As far as I can tell, PostCSS plugins would (ideally) just be a different means to the same end - we'd still effectively need to use it as a preprocessor. |
I think it would really help the non-Sass development workflow if we added as many custom properties as possible, allowing users to use Sass in more advanced use cases.
|
Hey everyone, there is clearly a lot of discussion that needs to be had over this problem. I don't think a GitHub issue is the right place to talk, because I keep looking at GitHub issues and thinking "How do I close them all!" But actually, this thread is a discussion, and not something that needs to be closed. So I propose the following: please use our "material-theming" channel (in the web category) in our Discord server. You can chat with us directly by following this link: https://discordapp.com/invite/material-components I'm going to close this issue now. So all future discussion about Sass, CSS-In-JS, custom properties, etc can happen in that channel. Also, as we have discussions, I will start filing more specific GitHub issues about tasks my team is working on. For example, I'll probably file a "Build a prototype using CSS-In-JS" issue soon, to show that we're looking into that specific technical detail. |
@lynnjepsen please do not direct discussions to a chat channel. There are three good reasons for this:
You could instead simply tag these issues as discussion type. |
Material-components-web is being ported to different libraries, including Vue, and it seems any library or framework other than React has been happily integrated with Sass.
It is known that the state of styles in React is a mess. This mess is two fold: First whether to write css in javascript. Seconds whether to process css by tools like Sass.
Another problem is starting a new project with React is hard. Hence, many of us opt to use CRA so that we can delegate dealing with nightmares like Webpack to other developers, which leads us to another problem: Weak or nonexisting support of Sass in CRA.
There are half baked approach for how to have Sass processing in CRA 1.x. None of them, including the one suggested in material-components-web-react guide, are ideal.
Sass is supposed to be supported in CRA 2.x, but it only works properly for the application code, and not for the npm packages that import sass files from other npm packages, which is the case of material-components-web-react components. Specifically see facebook/create-react-app#4651, facebook/create-react-app#4195 and facebook/create-react-app#4195 (comment).
Unfortunately, CRA authors are highly opinionated, inflexible and not very responsive when it comes to these Sass issues. At the moment, using material-components-web-react with CRA 1.x is possible with some hacks, and completely broken in CRA 2.x. Even Google project material-components-web-catalog uses an ejected version of CRA 1.x.
Given these high barriers, and given that Sass is a hard dependency of developing production quality with Material-components-web, the question is what can be done to stay away from Sass mess in React tools? Specifically, is it possible to change sass imports in material-components-web-react so that it can work with CRA 2.x, without CRA code being changes?
The text was updated successfully, but these errors were encountered: