File tree 1 file changed +17
-2
lines changed
dev-packages/rollup-utils/plugins
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change
1
+ import fs from 'fs' ;
2
+
1
3
/**
2
4
* Outputs a package.json file with {type: module} in the root of the output directory so that Node
3
5
* treats .js files as ESM.
4
6
*/
5
7
export function makePackageNodeEsm ( ) {
6
8
return {
7
9
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
+
9
24
this . emitFile ( {
10
25
type : 'asset' ,
11
26
fileName : 'package.json' ,
12
- source : '{ "type": "module", "sideEffects": false }' ,
27
+ source : JSON . stringify ( newPackageJSON ) ,
13
28
} ) ;
14
29
} ,
15
30
} ;
You can’t perform that action at this time.
0 commit comments