-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
How to use Modernizr with CRA? #2757
Comments
Does this comment and following comments help you? |
I came across the same problem today. I'm trying to figure out how to use Modernizr with CRA. As far as I can see the way to do it is to use modernizr-webpack-plugin. All the instructions on that page require modifying webpack.config.js and I believe the only way to do that is to eject CRA. I have been using CRA for about 4 months now (very satisfied) without ejecting and would hope to continue that way. @Timer the issue you references did not seem to address that. |
I'd like to understand this more, @klequis. Modernizr aside, what exactly are you trying to accomplish? We're very against allowing webpack configuration modifications; so if someone needs to make a new package or we can provide an alternative solution, I'd like to figure that out. |
Looking at these Modernizr webpack plugins, they seem completely redundant. |
@Timer I'm using Flexbox. It is working well in Firefox and Chrome but not in Safari. I can change the css from 'display: flex' to 'display: -webkit-box' and that fixes Safari well enough but makes a mess out of Firefox and Chrome. I want to use Modernizr to code in some conditional logic for the css. |
Thank you for the explanation!
Can you do this instead? |
Thank you for pointing that out. I imported it and now see changes the the html element caused by Modernizer so initially looks good. I didn't do any more than import and load the page. I'll try actually using Modernizer tomorrow and let you know if it works - Thank you! |
@klequis how did you import it? Can you post some code example of using it inside a js file? |
@sonarforte , the import seems to have worked but my feature checks are not working out. I posted a question on it Modernizr.flexbox in React app returns 'undefined' My sample project is here: https://github.com/klequis/modernizr-try The import is in src/App.js |
@klequis you shouldn't import the modernizr build like that since it is an IIFE. It means everytime you import the file it will excuse all the tests. In a context of a SPA you can end-up with lot of classes in the HTML tag as a result of multiple tests execution. In addition to that, the function doesn't return any value but attaches the result to the window object. That why you got nothing when accessing the props. I've created a fork of your repository and transformed the modernizr build into a module so you can import it into your app. Although this works, it is not ideal since you would have to do the same in case you recreate the build to add more tests for example, but it is a start. A better approach could be writing a client that modify the default modernizr build a generate a module as output. Hope this help! |
@fcaldera - More help than I expected - thank you! |
Isn't it a bit complicated to use modernizr to handle just css prefixing? Isn't this a task for Autoprefixer? |
I believe we got this resolved (in above comments). 😄 |
I've seen in many threads, when people ask to extend the webpack config, they are told to request the specific extension they need.
I'm looking to use Modernizr (as I'm willing to be other's are as well).
This package will bundle modernizr for use with webpack, but since I can't modify the webpack config in CRA, I have no idea how to include it.
Is there a way to do this?
The text was updated successfully, but these errors were encountered: