Material UI / Webpack / React - the className optimization/minification in production mode

我与影子孤独终老i 提交于 2021-02-09 07:23:28

问题


webpack - v4+
material ui - v4.9.6
react - v16.12.0

In a normal way all classes should be as the last one from the first example. In some reason on production mode, many of the classes do not change. Any idea?

Example 1:

<div class="MuiDrawer-root MuiDrawer-docked jss408"></div>

Example 2:

<div class="MuiPaper-root jss469 MuiPaper-elevation1 MuiPaper-rounded"></div>

回答1:


styles className is not designed as deterministic in prod mode.

But the generated class names of the @material-ui/core components behave differently. When the following conditions are met, the class names are deterministic:

  • Only one theme provider is used (No theme nesting)
  • The style sheet has a name that starts with Mui (all Material-UI components).
  • The disableGlobal option of the class name generator is false (the default).

Refer:

  • Document of Material-UI className generation
  • API of the generator creategenerateclassname


来源:https://stackoverflow.com/questions/60817202/material-ui-webpack-react-the-classname-optimization-minification-in-produ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!