According to the docs a RegExp passed as chunks is a short for (chunk) => regex.test(chunk.name) but you get a different between a regex and a function with the same regex.
After some debugging I found that I have chunks with name: undefined. This passes the regex check in JS but apparently not in Rust. If I change the chunks function to (chunk) => typeof chunk.name === "string" && regex.test(chunk.name) the result is aligned with the regex variant.
Reproduce link
No response
Reproduce Steps
Set any RegExp for splitChunks.chunks, build and check the generated assets
Set splitChunks.chunks to the same RegExp but in a function like (chunk) => regex.test(chunk.name), build and see different assets
System Info
System: OS: macOS 15.1.1 CPU: (12) arm64 Apple M3 Pro Memory: 10.48 GB / 36.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.9.0 - ~/.nvm/versions/node/v22.9.0/bin/node Yarn: 4.5.1 - ~/.nvm/versions/node/v22.9.0/bin/yarn npm: 10.8.3 - ~/.nvm/versions/node/v22.9.0/bin/npm Browsers: Chrome: 131.0.6778.86 Safari: 18.1.1 npmPackages: @rspack/cli: 1.1.3 => 1.1.3 @rspack/core: 1.1.3 => 1.1.3
Details
According to the docs a
RegExp
passed aschunks
is a short for(chunk) => regex.test(chunk.name)
but you get a different between a regex and a function with the same regex.After some debugging I found that I have chunks with
name: undefined
. This passes the regex check in JS but apparently not in Rust. If I change the chunks function to(chunk) => typeof chunk.name === "string" && regex.test(chunk.name)
the result is aligned with the regex variant.Reproduce link
No response
Reproduce Steps
splitChunks.chunks
, build and check the generated assetssplitChunks.chunks
to the same RegExp but in a function like(chunk) => regex.test(chunk.name)
, build and see different assets