October 23, 2024
Chicago 12, Melborne City, USA
javascript

How does Mui configure its exports without an `exports` property in the package.json?


In Mui’s documentation here they recommend using

import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';

style imports instead of

import { Button, TextField } from '@mui/material';

The reason for this, as I understand it, is that that @mui/material style import will ultimately go through a barrel file – and bundlers like Webpack:

  1. May not be able to treeshake accurately for production bundles
  2. Will not treeshake for development bundles, giving slower development build times.

Webpack respects a exports property in the package.json (documentation here) to declare submodules accessed via @mui/material/Button style imports.

However, Mui doesn’t actually appear to use these in their package.json

So how are these imports working?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video