Commit 3896cbe7 authored by Alex Castle's avatar Alex Castle Committed by Joe Haddad

Adjust lib chunk naming algorithm and prevent duplicate react-dom (#8450)

* Adjust lib chunk naming algorithm and prevent duplicate react-dom

* Remove alias for react-dom and update separator replacement logic

* Add comment to webpack-config
parent 3e912323
...@@ -220,6 +220,9 @@ export default async function getBaseWebpackConfig( ...@@ -220,6 +220,9 @@ export default async function getBaseWebpackConfig(
default: false, default: false,
vendors: false, vendors: false,
framework: { 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',
name: 'framework', name: 'framework',
test: /[\\/]node_modules[\\/](react|react-dom|scheduler|prop-types)[\\/]/, test: /[\\/]node_modules[\\/](react|react-dom|scheduler|prop-types)[\\/]/,
priority: 40, priority: 40,
...@@ -232,20 +235,22 @@ export default async function getBaseWebpackConfig( ...@@ -232,20 +235,22 @@ export default async function getBaseWebpackConfig(
) )
}, },
name(module: { identifier: Function; rawRequest: string }): string { name(module: { identifier: Function; rawRequest: string }): string {
const rawRequest =
module.rawRequest &&
module.rawRequest.replace(/^@(\w+)[/\\]/, '$1-')
if (rawRequest) return rawRequest
const identifier = module.identifier() const identifier = module.identifier()
// Remove everything up through '/node_modules/'
const trimmedIdentifier = /(?:^|[/\\])node_modules[/\\](.*)/.exec( const trimmedIdentifier = /(?:^|[/\\])node_modules[/\\](.*)/.exec(
identifier identifier
) )
const processedIdentifier = const processedIdentifier =
trimmedIdentifier && 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, priority: 30,
minChunks: 1, minChunks: 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment