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 lib chunk naming algorithm and prevent duplicate react-dom #8450

Merged
merged 4 commits into from
Aug 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export default async function getBaseWebpackConfig(
default: false,
vendors: false,
framework: {
// Framework chunk applies to modules in dynamic chunks, unlike shared chunks
// TODO(atcastle): Analyze if other cache groups should be set to 'all' as well
chunks: 'all',
atcastle marked this conversation as resolved.
Show resolved Hide resolved
name: 'framework',
test: /[\\/]node_modules[\\/](react|react-dom|scheduler|prop-types)[\\/]/,
priority: 40,
Expand All @@ -232,20 +235,22 @@ export default async function getBaseWebpackConfig(
)
},
name(module: { identifier: Function; rawRequest: string }): string {
const rawRequest =
module.rawRequest &&
module.rawRequest.replace(/^@(\w+)[/\\]/, '$1-')
if (rawRequest) return rawRequest

Choose a reason for hiding this comment

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

            // avoid relative paths
            if (rawRequest && rawRequest[0] !== '.') {
              return rawRequest;
            }

Copy link
Member

Choose a reason for hiding this comment

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

How do you feel about just dropping the names all together?

#8450 (comment)


const identifier = module.identifier()
// Remove everything up through '/node_modules/'
const trimmedIdentifier = /(?:^|[/\\])node_modules[/\\](.*)/.exec(
identifier
)
const processedIdentifier =
trimmedIdentifier &&
trimmedIdentifier[1].replace(/^@(\w+)[/\\]/, '$1-')
// Remove the file extension(s)
/[\w-\/\\]+/.exec(trimmedIdentifier[1])

let finalName = processedIdentifier && processedIdentifier[0]

finalName = finalName && finalName.replace(/[\\\/]/g, '~')
const backupName = identifier.replace(/[\\\/]/g, '~')

return processedIdentifier || identifier
return finalName || backupName
},
priority: 30,
minChunks: 1,
Expand Down