mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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.
7 lines
130 B
JSON
7 lines
130 B
JSON
{
|
|
"removeUnusedImports": true,
|
|
"removeUnusedExports": true,
|
|
"cjsTreeShaking": true,
|
|
"treeShakingMode": "reexports-only"
|
|
}
|