Search code examples
javascriptreactjsmaterial-uiparceljs

Material-UI production build generate different styles order definition than in development


Using material-ui, the production build differs from the development one: the generated material-ui styles in production are not defined in the same order as ones from development one.

In DEV, the HTML head tag contains the material-ui styles in this order:

  • MuiPaper
  • MuiTouchRipple
  • MuiButtonBase
  • MuiButton
  • [...]

In PROD, the HTML head tag contains the material-ui styles in this order:

  • MuiButton
  • MuiButtonBase
  • MuiIcon
  • MuiMenu
  • [...]

So in production, it breaks styles: material-ui own styles are overriding one another...

Some more context:

My question: how can I make sure material-ui styles are rendered the same way in development and in production ?


Solution

  • The solution was actually to upgrade to the v5 of Material-ui: https://next.material-ui.com/guides/migration-v4/

    The root issue seemed to be related to Material-ui v4 not correctly handling tree-shaking: https://github.com/mui-org/material-ui/issues/16609