File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
dev-packages/rollup-utils/plugins Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 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 */
57export 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 } ;
You can’t perform that action at this time.
0 commit comments