-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
REACT with CRA incorrect webpack config for SCSS - loaders not working #3985
Comments
material-components does not follow the webpack standard so it is not compatible with webpack unless you have access to the webpack config which might be difficult for large angular or react projects. Without the loader option you would still be able to resolve packages from the node_modules folders using a
However material-components is also using the
create react app uses the webpack standard for scss imports so you won't be able to combine create-react-app and material-components. |
You might be able to get everything working with CRA and MDC Web by following the getting started guide from the Material Components for React repo. I believe there's currently a way to do without ejecting. Using our components with Angular is also pretty straightforward but does require you to manually edit the |
Is there any chance to switch to the webpack standard and add that strange Then it would work without setting scss include paths |
We explored that option at one point but discovered the tilde ( |
Already did that in the code and still didnt work |
@williamernest that's true but is ruby still used? |
Rails users still use npm to install their node dependencies and then use rubysass to compile their sass files. Rubysass doesn't support the tilde. We do have users that are using rails and our components. @CasperGrey Can you tell me what you've tried or reproduce it in a separate repo? I'd like to get you working but it's sometimes easier to just look at the code. |
Here is the create-react-app (CRA) webpack.config.js (which can't be changed unless you eject): |
Here's the MDC React workaround for compiling sass without ejecting. |
@CasperGrey Here is a sample ejected CRA2 project that uses MDC SASS/RMWC. https://github.com/robcaldecott/rmwc-cra2-example The trick is the following change to the webpack config to include webpack.config.dev.js, line 62 if (preProcessor) {
loaders.push({
loader: require.resolve(preProcessor),
options: { includePaths: [paths.appNodeModules] }
});
} webpack.config.prod.js, line 87 if (preProcessor) {
loaders.push({
loader: require.resolve(preProcessor),
options: {
sourceMap: shouldUseSourceMap,
includePaths: [paths.appNodeModules]
}
});
} |
FWIW I might publish a CRA2 |
@CasperGrey here you go (forked CRA2): yarn create react-app my-app --scripts-version mdc-react-scripts You can import the Material SASS without it throwing errors. HTH. |
@CasperGrey nice work! I tried it out and can confirm it works. Do you intend to open a PR to the official CRA? |
How will this work with mono repo approaches like lerna? |
@moog16 Someone tried a similar PR for CRA2 but it was rejected and they cited the @jantimon I've just pushed 2.1.0 of |
@jantimon I just tried lerna (with and without |
@robcaldecott can you share the PR you're talking about? |
@moog16 This one: facebook/create-react-app#5011 However, there is a new PR in flight which prompted a discussion about supporting facebook/create-react-app#5599 It would be good to not have to eject or fork. Another option is |
There's also facebook/create-react-app#4494 which looks relevant. On a quick glance it looks like node-sass does support SASS_PATH... interestingly, it looks like dart-sass might not currently? (Update: Logged sass/dart-sass#512) I'm a tiny bit concerned of the usability of SASS_PATH if it needs to be absolute paths, when |
@kfranqueiro I just tried the It will be interesting to see what happens to that PR. |
Closed this issue since we updated our guidelines in material-components/material-components-web-react#393. This is a step-by-step guide on how to setup CRA-2 on Linux, MacOSX, and Windows and use MDC Web and React Sass files. Please find new steps in the React Repo's README. Also Thanks @robcaldecott for figuring out the |
Hi,
I am currently using a CRA based app that im trying to use Material components web with. I have edited my dev config to include the suggested changes to the scss loaders but still i am getting the following compile error suggesting webpack is not able to find the correct modules..
My webpack.config.dev.js and package.json
https://codepen.io/ben-johnston/pen/dggJPp
Can anyone assist in the correct config to make this work?
The text was updated successfully, but these errors were encountered: