Skip to content
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] Modularize Imports for Nextjs #35457

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,30 @@ Modify your `package.json` commands:
}
```

If you are using Nextjs >= v12.1.1, you can make use of their [Modularize Imports](https://nextjs.org/docs/advanced-features/compiler#modularize-imports) without `.babelrc` configuration, so that you can still use [SWC](https://nextjs.org/docs/advanced-features/compiler#why-swc).
dev-ahmedhany marked this conversation as resolved.
Show resolved Hide resolved

Create a `next.config.js` file in the root directory:

```js
/* next.config.js */
/** @type {import('next').NextConfig} */
const nextConfig = {
...
experimental: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seems to be under experimental in https://nextjs.org/docs/advanced-features/compiler#modularize-imports

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recently promoted

modularizeImports: {
'@mui/material': {
transform: '@mui/material/{{member}}'
},
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down