rslib icon indicating copy to clipboard operation
rslib copied to clipboard

[Bug]: multiple entries mode will compose duplicate files into each entries that imported that file

Open turnerguo opened this issue 1 year ago • 1 comments

Version

System:
    OS: macOS 14.6.1
  Browsers:
    Chrome Canary: 133.0.6917.0
    Edge: 131.0.2903.112
  npmPackages:
    @rslib/core: 0.2.0 => 0.2.0

Details

Assuming we have a library package like this:

// ./src
//   - common
//     - utils.ts
//   - components-a
//     - buttons-a.ts -> utils.ts
//   - components-b
//     - buttons-b.ts -> utils.ts

// rslib.config.ts
...
source: {
       entry: {
         index: ['./src/**', '!./**/__test__/**'],
       },
    },
...

after build the utils.ts file will compiled into both components-a and components-b, in vite it will automatically split utils.ts as a reusable file, this is actually truly expected.

Reproduce link

https://codepen.io/Justineo/pen/yLbxxOR

Reproduce Steps

execute rslib build

turnerguo avatar Dec 25 '24 12:12 turnerguo

Your entry configuration above is usually used for bundleless mode, the correct entry config should be:

source: {
  entry: {
    'components-a': './src/components-a/buttons-a.ts',
    'components-b': './src/components-b/buttons-b.ts',
  },
},

This should be the issue you want to describe.

The bundled output components-a.js and components-b.js will both contain code in utils.ts. Splitting is not supported now, we will improve that in webpack/Rspack in the future. See https://github.com/web-infra-dev/rslib/issues/45.

Timeless0911 avatar Dec 26 '24 05:12 Timeless0911

Split chunks in bundle mode is supported via #1273 .

Timeless0911 avatar Oct 30 '25 07:10 Timeless0911