[Bug]: multiple entries mode will compose duplicate files into each entries that imported that file
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
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.
Split chunks in bundle mode is supported via #1273 .