Skip to content

Commit a95a2cd

Browse files
Merge pull request #183 from preactjs/commonjs-regression
Revert back to old commonjs behaviour.
2 parents 742087f + 57af297 commit a95a2cd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

config/node-commonjs.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"scripts": {
2525
"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",
2727
"transpile": "microbundle src/index.js -f es,umd --target web --external preact",
2828
"transpile:jsx": "microbundle src/jsx.js -o dist/jsx.js --target web --external none && microbundle dist/jsx.js -o dist/jsx.js -f cjs",
2929
"copy-typescript-definition": "copyfiles -f src/*.d.ts dist",

0 commit comments

Comments
 (0)