Creating npm package for typescript based library in 2024
Published On: 13 Jul 2024
Reading Time: 1 minutes
Overview
To create typescript based packages that are compatible with both ECMAScript Modules (ESM) and CommonJS (CJS) you can use the following configuration:
{
"name": "my-npm-package",
"version": "1.0.0",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
"watch": "npm run build -- --watch src",
"prepublishOnly": "npm run build"
},
"keywords": [],
"author": "",
"license": "Apache-2.0"
}
Reference
Page Views: -
javascript typescript npm nodejs
Related Articles
Monorepo alternative to sharing routes for NextJs 14 in 2024
How you can achieve code sharing at page level without setting up a monorepo using Nextjs 14 colocation capability
28/07/2024
The Evolution of Web Development
Isomorphic JavaScript, SSR, Hydration, and Resumability
23/07/2024
CASL Ability Based Http Client to secure NextJS server actions
Explore how to use the AbilityBasedHttpClient class to integrate access control into your API requests using CASL and TypeScript.
08/10/2024
How to setup a Nextjs 14 custom server
Steps to setup custom Next.js server
24/07/2024