-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[docs] Modularize Imports for Nextjs #35457
Changes from 2 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 |
---|---|---|
|
@@ -194,6 +194,31 @@ Modify your `package.json` commands: | |
} | ||
``` | ||
|
||
If you are using Next.js >= v12.1.1, you can make use of their [Modularize Imports](https://nextjs.org/docs/advanced-features/compiler#modularize-imports) feature. | ||
This does not require adding Babel configuration, so you can still use [SWC](https://nextjs.org/docs/advanced-features/compiler#why-swc) if you prefer. | ||
|
||
Create a `next.config.js` file in the root directory: | ||
|
||
```js | ||
/* next.config.js */ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
... | ||
experimental: { | ||
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. It doesn't seems to be under 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. It's recently promoted |
||
modularizeImports: { | ||
'@mui/material': { | ||
transform: '@mui/material/{{member}}' | ||
}, | ||
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. I wouldn't do this, this is probably overkill. There are also cases where it doesn't work because the code is not consistent enough. |
||
'@mui/icons-material': { | ||
transform: '@mui/icons-material/{{member}}' | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = nextConfig | ||
``` | ||
|
||
Enjoy significantly faster start times. | ||
|
||
#### 2. Convert all your imports | ||
|
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.
This section of the docs starts to be quite long. I think that it could be good to change the headers to help navigate the content.