Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created March 11, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoisryosuke/1ccfe297f04c7c651ae352c0a4ee3f51 to your computer and use it in GitHub Desktop.
Save whoisryosuke/1ccfe297f04c7c651ae352c0a4ee3f51 to your computer and use it in GitHub Desktop.
Typescript/NPM - How to build both ESM and CJS in project. @see https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html
tsc -p tsconfig.json && tsc -p tsconfig-cjs.json
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"target": "es2015"
}
}
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs",
"target": "esnext"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment