How to use materialize-css with React?

后端 未结 13 1808
太阳男子
太阳男子 2020-12-07 17:52

I have a Meteor/React project, using ES6 modules. I\'ve installed materialize-css using npm, but I\'m not sure how to actually use the Materialize classes in my JSX code. Wh

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 18:16

    These answers didn't satisfy my biggest concern which was bundle size and importing a ton of code in order to use a few components. I've written up a solution here that includes code splitting and an easy compilation step.

    The key points are:

    1. Compile base JS files (there are 4)
    2. Ensure the base JS is included before your imports / bundler runs
    3. Change the CSS imports to only what you need
    4. Run materialize.scss through your bundler if it supports Sass or run the compilation step to get a minified css file.
    5. Import individual components and activate them manually

    Read post for more details.

提交回复
热议问题