rsbuild
rsbuild copied to clipboard
[Bug]: match unexpected environment resources when serving
Version
rsbuild 1.0 beta
Details
When multiple environments exist and their products are dist/main.js (web product) and dist/bundle/main.js (node product)
expect:
- Match
dist/main.jswhen accessinglocalhost:3000/mian - Match
dist/bundle/main.jswhen accessinglocalhost:3000/bundle/mian
actual:
- Matches
dist/bundle/main.jswhen accessinglocalhost:3000/mian(unexpected) - Match
dist/bundle/main.jswhen accessinglocalhost:3000/bundle/mian
The rsbuild configuration is as follows:
import { defineConfig } from '@rsbuild/core';
export default defineConfig({
environments: {
node: {
output: {
distPath: {
root: 'dist/bundle',
},
},
},
web: {},
},
});
Reproduce link
none
Reproduce Steps
The root cause of this problem is that when using multiCompiler(Multiple rsbuild environments), webpack-dev-middleware matches resources based on the outputPath + publicPath of each compiler. When the environment node is created before the web, webpack-dev-middleware preferentially matches the resources in node stats.
https://github.com/webpack/webpack-dev-middleware/blob/master/src/utils/getFilenameFromUrl.js#L68
This can be temporarily solved by adjusting the environment registration order.