File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' ) ;
2
+ const path = require ( 'path' ) ;
3
+
4
+ // This file will only export default exports in commonjs bundles
5
+ // instead of guarding them behind a `.default` property.
6
+
7
+ const filePath = ( file ) => path . join ( process . cwd ( ) , 'dist' , file ) ;
8
+
9
+ // Main entry
10
+ fs . copyFileSync ( filePath ( 'index.js' ) , filePath ( 'commonjs.js' ) ) ;
11
+ fs . copyFileSync ( filePath ( 'index.js.map' ) , filePath ( 'commonjs.js.map' ) ) ;
12
+
13
+ const source = `module.exports = require('./commonjs').default;` ;
14
+ fs . writeFileSync ( filePath ( 'index.js' ) , source , 'utf-8' ) ;
15
+
16
+ // JSX entry
17
+ fs . copyFileSync ( filePath ( 'jsx.js' ) , filePath ( 'jsx-entry.js' ) ) ;
18
+ fs . copyFileSync ( filePath ( 'jsx.js.map' ) , filePath ( 'jsx-entry.js.map' ) ) ;
19
+
20
+ const sourceJsx = `module.exports = require('./jsx-entry').default;` ;
21
+ fs . writeFileSync ( filePath ( 'jsx.js' ) , sourceJsx , 'utf-8' ) ;
Original file line number Diff line number Diff line change 23
23
},
24
24
"scripts" : {
25
25
"build" : " npm run -s transpile && npm run -s transpile:jsx && npm run -s copy-typescript-definition" ,
26
- "postbuild" : " node ./config/node-13-exports.js" ,
26
+ "postbuild" : " node ./config/node-13-exports.js && node ./config/node-commonjs.js " ,
27
27
"transpile" : " microbundle src/index.js -f es,umd --target web --external preact" ,
28
28
"transpile:jsx" : " microbundle src/jsx.js -o dist/jsx.js --target web --external none && microbundle dist/jsx.js -o dist/jsx.js -f cjs" ,
29
29
"copy-typescript-definition" : " copyfiles -f src/*.d.ts dist" ,
You can’t perform that action at this time.
0 commit comments