rsbuild icon indicating copy to clipboard operation
rsbuild copied to clipboard

[Bug]: match unexpected environment resources when serving

Open 9aoy opened this issue 1 year ago • 0 comments

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.js when accessing localhost:3000/mian
  • Match dist/bundle/main.js when accessing localhost:3000/bundle/mian

actual:

  • Matches dist/bundle/main.js when accessing localhost:3000/mian (unexpected)
  • Match dist/bundle/main.js when accessing localhost: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.

image

image

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.

9aoy avatar Jul 18 '24 08:07 9aoy