Skip to content

Commit

Permalink
feat: build and package cjs version
Browse files Browse the repository at this point in the history
  • Loading branch information
vai-eerau authored and iiroj committed May 30, 2023
1 parent 2861141 commit d5b6d29
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
12 changes: 12 additions & 0 deletions package-fixup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >dist/mjs/package.json <<!EOF
{
"type": "module"
}
!EOF
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"type": "module",
"main": "./dist/index.js",
"main": "./dist/cjs/index.js",
"module": "/dist/mjs/index.js",
"exports": {
".": "./dist/index.js"
".": {
"types": "./dist/index.d.ts",
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"types": "./dist/index.d.ts",
"files": [
Expand All @@ -29,7 +33,9 @@
"lint": "npm run lint:base -- .",
"typecheck": "tsc -p tsconfig.json --noEmit",
"test": "jest",
"build": "tsc --build tsconfig.build.json"
"build:esm": "tsc --build tsconfig.mjs.json",
"build:cjs": "tsc --build tsconfig.cjs.json",
"build": "npm run build:esm && npm run build:cjs && ./package-fixup.sh"
},
"peerDependencies": {
"react": ">=16.8",
Expand Down
14 changes: 14 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declarationDir": "dist",
"noEmit": false,
"module": "CommonJS",
"target": "ES6",
"lib": ["dom", "ES6"],
"outDir": "dist/cjs"
},
"include": [
"src/**/*.ts"
]
}
2 changes: 1 addition & 1 deletion tsconfig.build.json → tsconfig.mjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"declarationDir": "dist",
"noEmit": false,
"outDir": "dist",
"outDir": "dist/mjs",
"rootDir": "src"
},
"include": [
Expand Down

0 comments on commit d5b6d29

Please sign in to comment.