Skip to content

Commit 558ec88

Browse files
committed
use side effects from original package.json
1 parent 6ed3d1d commit 558ec88

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

dev-packages/rollup-utils/plugins/make-esm-plugin.mjs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
import fs from 'fs';
2+
13
/**
24
* Outputs a package.json file with {type: module} in the root of the output directory so that Node
35
* treats .js files as ESM.
46
*/
57
export function makePackageNodeEsm() {
68
return {
79
name: 'make-package-node-esm',
8-
generateBundle() {
10+
async generateBundle() {
11+
// We need to keep the `sideEffects` value from the original package.json,
12+
// as e.g. webpack seems to depend on this
13+
// without this, tree shaking does not work as expected
14+
const packageJSONPath = (await this.resolve('package.json')).id;
15+
16+
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'));
17+
const sideEffects = packageJSON.sideEffects;
18+
19+
const newPackageJSON = {
20+
type: 'module',
21+
sideEffects,
22+
};
23+
924
this.emitFile({
1025
type: 'asset',
1126
fileName: 'package.json',
12-
source: '{ "type": "module", "sideEffects": false }',
27+
source: JSON.stringify(newPackageJSON),
1328
});
1429
},
1530
};

0 commit comments

Comments
 (0)