[turbopack] Drop dead `require()` calls (#95718)
This PR adds support for `turbopackRemoveUnusedImports` in CJS modules.
If modules are side-effect free and their imports are unused we do the
following re-writes:
```
require('./pure') → 0;
console.log('x') console.log('x')
```
```
const x = require('./pure') → const x = 0
```
```
const dead = require('./pure'), keep = 'v' → const dead = 0, keep = 'v'
```
```
const {} = require('./pure') → const {} = 0
```
```
if (cond) require('./pure') → if (cond) 0;
```
SWC should then drop the 0.
Showing
Please
register
or
sign in
to comment