-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] Adding tree shaking guide for SWC compiler #36456
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -207,6 +207,57 @@ It will perform the following diffs: | |||||||||||
+import { Button, TextField } from '@mui/material'; | ||||||||||||
``` | ||||||||||||
|
||||||||||||
### Option three: use a SWC plugin | ||||||||||||
|
||||||||||||
This option pretty much similar to the option two, except for the developer who is using [SWC Compiler](https://swc.rs/). Use this [plugin](https://github.com/swc-project/plugins/blob/main/packages/transform-imports/README.md): | ||||||||||||
|
||||||||||||
`yarn add -D @swc/plugin-transform-imports` | ||||||||||||
|
||||||||||||
Modify your .swcrc or Webpack configuration: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Below we are showing the config for Webpack, so mentioning
Suggested change
|
||||||||||||
|
||||||||||||
```js | ||||||||||||
/* webpack.config.js */ | ||||||||||||
const webpackConfig = { | ||||||||||||
// ... | ||||||||||||
module: { | ||||||||||||
rules: [ | ||||||||||||
...{ | ||||||||||||
test: /\.tsx?$/, | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include Javascript files as well:
Suggested change
|
||||||||||||
use: [ | ||||||||||||
Comment on lines
+225
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we exclude
Suggested change
|
||||||||||||
{ | ||||||||||||
loader: 'swc-loader', | ||||||||||||
options: { | ||||||||||||
jsc: { | ||||||||||||
experimental: { | ||||||||||||
plugins: [ | ||||||||||||
[ | ||||||||||||
require.resolve('@swc/plugin-transform-imports'), | ||||||||||||
{ | ||||||||||||
'@mui/material': { | ||||||||||||
transform: '@mui/material/{{member}}', | ||||||||||||
}, | ||||||||||||
'@mui/icons-material': { | ||||||||||||
transform: '@mui/icons-material/{{member}}', | ||||||||||||
}, | ||||||||||||
// For styled, useTheme etc | ||||||||||||
'@mui/system': { | ||||||||||||
transform: '@mui/system/{{member}}', | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
], | ||||||||||||
], | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
], | ||||||||||||
}, | ||||||||||||
], | ||||||||||||
}, | ||||||||||||
}; | ||||||||||||
module.exports = webpackConfig; | ||||||||||||
``` | ||||||||||||
|
||||||||||||
## Available bundles | ||||||||||||
|
||||||||||||
The package published on npm is **transpiled**, with [Babel](https://github.com/babel/babel), to take into account the [supported platforms](/material-ui/getting-started/supported-platforms/). | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we also need
@swc/core
andswc-loader
dependencies?