Skip to content

Information: solving jss classnames production build conflict with external MUI dependent component #11628

@nihaux

Description

@nihaux

So I spend the all afternoon reading the related issues and debugging my code so I am posting this here in case it helps someone.
I can make a PR for the doc if you want but don't know where it should go as it is not directly a MUI issue.

Use case:

  • I have an external component "mui-tree-list" which use mui v1.
  • The lib use rollup to package the component.
  • in the rollup config I put
    external: [ 'react', '@material-ui/core', '@material-ui/icons', 'react-dom' ],
    WRONG ! ;p

If you do this, you'll end up having jss classname conflicts in the production build of you final app.

why ?

cause @material-ui/core does not avoid @material-ui/core/List for instance to be included in your dist package.

and @material-ui/core/List will include withStyles which will cause jss class naming conflict in your final package !

So the solution is, you should put this in your rollup config:
external: id => /react|react-dom|material-ui\/.*/.test(id),

this way all material-ui components will be excluded from your build... lost some hair with this one :p .

Metadata

Metadata

Labels

docsImprovements or additions to the documentation.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions