Skip to content

Commit

Permalink
Add mjs support (#30)
Browse files Browse the repository at this point in the history
* Add mjs support

* FIx typos
  • Loading branch information
followdarko authored Jul 9, 2021
1 parent f68e141 commit b85e37e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 15 additions & 0 deletions config/node-13-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require('fs');

const snakeCaseToCamelCase = str =>
str.replace(/([-_][a-z])/g, group => group.toUpperCase().replace('-', ''));

const copy = name => {
// Copy .module.js --> .mjs for Node 13 compat.
const filename = name.includes('-') ? snakeCaseToCamelCase(name) : name;
fs.writeFileSync(
`${process.cwd()}/dist/${filename}.mjs`,
fs.readFileSync(`${process.cwd()}/dist/${filename}.module.js`)
);
};

copy('index');
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
"module": "dist/index.module.js",
"umd:main": "dist/index.umd.js",
"source": "src/index.js",
"exports": {
".": {
"browser": "./dist/index.module.js",
"umd": "./dist/index.umd.js",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"types": "typings/index.d.ts",
"files": [
"dist",
Expand All @@ -31,7 +39,8 @@
"build:clean": "rimraf dist",
"build:bundle": "microbundle -i src/index.js --external preact --compress --strict --name preactSsrPrepass",
"build:flow": "flow-copy-source -i '*.test.js' src/ dist/",
"prepublishOnly": "npm run test && npm run build"
"prepublishOnly": "npm run test && npm run build",
"postbuild": "node ./config/node-13-exports.js"
},
"peerDependencies": {
"preact": ">=10 || ^10.0.0-beta.0 || ^10.0.0-alpha.0"
Expand Down

0 comments on commit b85e37e

Please sign in to comment.