web-infra-dev / web-infra-dev/rspack
[Feature][Treeshaking]: re-assignment breaks treeshaking
Open
@JSerFeng is already working on this.
Since Apr 7, 2025.
team
- Dominant language
- Rust
- Stars
- 12.9k
- Forks
- 854
- Avg merge
- 20h 48m
- Merged PRs (30d)
- 316
Description
Details
{
"sideEffects": ["a.mjs"]
}
1. without re-assignment
// ./src/barrel.mjs
import { a } from './a.mjs';
import { b } from './b.mjs';
// a is unused
export { a, b };
// ./src/index.mjs
import { b } from './barrel.mjs'
console.log(b);
output:
;// CONCATENATED MODULE: ./src/b.mjs
const b = 2;
console.log(b)
2. with re-assignment
// ./src/barrel.mjs
import { a } from './a.mjs';
import { b } from './b.mjs';
// a is unused
const __webpack_exports__a__ = a;
const __webpack_exports__b__ = b;
export { __webpack_exports__a__ as a , __webpack_exports__b__ as b };
// ./src/index.mjs
import { b } from './barrel.mjs'
console.log(b);
output:
;// CONCATENATED MODULE: ./src/a.mjs
const a_a = 2;
window.a = a_a;
;// CONCATENATED MODULE: ./src/b.mjs
const b = 2;
console.log(b)
Reproduction
see https://github.com/SoonIter/rspack-reassign-treeshaking-issue
which is a minimal production of https://github.com/SoonIter/rslib-css-modules-treeshaking
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.