From 313075260a718f376081f4acbdd2cf782625b256 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 7 Jun 2023 14:23:08 +0200 Subject: [PATCH 1/4] Add default modularizeImports that breaks up lucide-react, mui/icons-material, lodash, react-bootstrap --- packages/next/src/server/config.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/next/src/server/config.ts b/packages/next/src/server/config.ts index 908f26732fa32..3e9ae2ef57820 100644 --- a/packages/next/src/server/config.ts +++ b/packages/next/src/server/config.ts @@ -666,6 +666,26 @@ function assignDefaults( } } + const userProvidedModularizeImports = result.modularizeImports + // Unfortunately these packages end up re-exporting 10600 modules, for example: https://unpkg.com/browse/@mui/icons-material@5.11.16/esm/index.js. + // Leveraging modularizeImports tremendously reduces compile times for these. + result.modularizeImports = { + ...(userProvidedModularizeImports || {}), + // This is intentionally added after the user-provided modularizeImports config. + 'lucide-react': { + transform: 'lucide-react/dist/esm/icons/{{ kebabCase member }}', + }, + '@mui/icons-material/?(((\\w*)?/?)*)': { + transform: '@mui/icons-material/{{ matches.[1] }}/{{member}}', + }, + lodash: { + transform: 'lodash/{{member}}', + }, + 'react-bootstrap': { + transform: 'react-bootstrap/{{member}}', + }, + } + return result } From cbf28e27329effda3ffaf404fc87601e13b29fd2 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 7 Jun 2023 19:23:06 +0200 Subject: [PATCH 2/4] Add additional packages --- packages/next/src/server/config.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/next/src/server/config.ts b/packages/next/src/server/config.ts index 3e9ae2ef57820..bd94a6f65e01b 100644 --- a/packages/next/src/server/config.ts +++ b/packages/next/src/server/config.ts @@ -672,15 +672,27 @@ function assignDefaults( result.modularizeImports = { ...(userProvidedModularizeImports || {}), // This is intentionally added after the user-provided modularizeImports config. - 'lucide-react': { - transform: 'lucide-react/dist/esm/icons/{{ kebabCase member }}', - }, '@mui/icons-material/?(((\\w*)?/?)*)': { transform: '@mui/icons-material/{{ matches.[1] }}/{{member}}', }, + '@mui/material': { + transform: '@mui/material/{{member}}', + }, + 'date-fns': { + transform: 'date-fns/{{member}}', + }, lodash: { transform: 'lodash/{{member}}', }, + 'lodash-es': { + transform: 'lodash-es/{{member}}', + }, + 'lucide-react': { + transform: 'lucide-react/dist/esm/icons/{{ kebabCase member }}', + }, + ramda: { + transform: 'ramda/es/{{member}}', + }, 'react-bootstrap': { transform: 'react-bootstrap/{{member}}', }, From 818017d80ab58975cf4425d72007d05dee21c2e9 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 7 Jun 2023 19:33:45 +0200 Subject: [PATCH 3/4] Update config.ts --- packages/next/src/server/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/server/config.ts b/packages/next/src/server/config.ts index bd94a6f65e01b..658c0c3672480 100644 --- a/packages/next/src/server/config.ts +++ b/packages/next/src/server/config.ts @@ -672,8 +672,8 @@ function assignDefaults( result.modularizeImports = { ...(userProvidedModularizeImports || {}), // This is intentionally added after the user-provided modularizeImports config. - '@mui/icons-material/?(((\\w*)?/?)*)': { - transform: '@mui/icons-material/{{ matches.[1] }}/{{member}}', + '@mui/icons-material': { + transform: '@mui/icons-material/{{member}}', }, '@mui/material': { transform: '@mui/material/{{member}}', From d55ac66dcd6fc6a6c1da75786e53b217a8837f4b Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Fri, 23 Jun 2023 21:17:44 +0200 Subject: [PATCH 4/4] disable lucide-react for now --- packages/next/src/server/config.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/next/src/server/config.ts b/packages/next/src/server/config.ts index 474ac4b3b7e96..f03f2a5a3ee9c 100644 --- a/packages/next/src/server/config.ts +++ b/packages/next/src/server/config.ts @@ -694,9 +694,11 @@ function assignDefaults( 'lodash-es': { transform: 'lodash-es/{{member}}', }, - 'lucide-react': { - transform: 'lucide-react/dist/esm/icons/{{ kebabCase member }}', - }, + // TODO: Enable this once we have a way to remove the "-icon" suffix from the import path. + // Related discussion: https://github.com/vercel/next.js/pull/50900#discussion_r1239656782 + // 'lucide-react': { + // transform: 'lucide-react/dist/esm/icons/{{ kebabCase member }}', + // }, ramda: { transform: 'ramda/es/{{member}}', },