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

Adjust optimizePackageImports #55040

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ function getOptimizedAliases(): { [pkg: string]: string } {
}

// Alias these modules to be resolved with "module" if possible.
function getModularizeImportAliases(packages: string[]) {
function getBarrelOptimizationAliases(packages: string[]) {
const aliases: { [pkg: string]: string } = {}
const mainFields = ['module', 'main']

Expand All @@ -492,7 +492,7 @@ function getModularizeImportAliases(packages: string[]) {

for (const field of mainFields) {
if (descriptionFileData.hasOwnProperty(field)) {
aliases[pkg] = path.join(
aliases[pkg + '$'] = path.join(
Copy link
Member

Choose a reason for hiding this comment

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

This is for regex termination, right?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's webpack alias syntax https://webpack.js.org/configuration/resolve/#resolvealias , this only matches the imports from module name

path.dirname(descriptionFilePath),
descriptionFileData[field]
)
Expand Down Expand Up @@ -1142,7 +1142,7 @@ export default async function getBaseWebpackConfig(
// For Node server, we need to re-alias the package imports to prefer to
// resolve to the ESM export.
...(isNodeServer
? getModularizeImportAliases(
? getBarrelOptimizationAliases(
config.experimental.optimizePackageImports || []
)
: {}),
Expand Down
9 changes: 7 additions & 2 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,19 @@ function assignDefaults(
...userProvidedOptimizePackageImports,
'lucide-react',
'@headlessui/react',
'@fortawesome/fontawesome-svg-core',
'@fortawesome/free-solid-svg-icons',
'@headlessui-float/react',
'@heroicons/react/20/solid',
'@heroicons/react/24/solid',
'@heroicons/react/24/outline',
'@visx/visx',
'@tremor/react',
'rxjs',
'@mui/material',
shuding marked this conversation as resolved.
Show resolved Hide resolved
'recharts',
'@material-ui/core',
'react-use',
'@material-ui/icons',
'@tabler/icons-react',
]),
]

Expand Down