Skip to content

Commit

Permalink
Add esm build configuration and package.json exports (#201)
Browse files Browse the repository at this point in the history
This will build a cjs compatible bundle and an esm compatible bundle and package them both, allowing downstream projects to import the module type that fits their project.
  • Loading branch information
aethr authored Oct 23, 2024
1 parent d68b7d3 commit 664e2d5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@
"type": "git",
"url": "https://github.com/jscheiny/safe-units.git"
},
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"files": [
"dist"
],
"scripts": {
"build": "tsc -p src",
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > dist/esm/package.json",
"build": "yarn run build:cjs && yarn run build:esm",
"clean": "rimraf dist docs/build",
"compile:docs": "tsc -p docsgen",
"compile:examples": "tsc -p docs/examples",
Expand Down
13 changes: 11 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"declarationDir": "./dist/types",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
Expand All @@ -18,5 +19,13 @@
"es2015",
"es2015.core"
]
}
},
"include": [
"src"
],
"exclude": [
"dist",
"node_modules",
"test"
]
}
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./dist/cjs",
"target": "ES2015"
}
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "es6",
"outDir": "./dist/esm",
"target": "es6"
}
}

0 comments on commit 664e2d5

Please sign in to comment.