tsup-template
Create a JavaScript package that fully supports ESM and CJS - example
Quick Start
- Click the
Use this template
button - Clone the newly created repository
npm i
— install the dependencies- Set package data in
package.json
- Write library code in
/src/index.ts
npm version
— bump package versionnpm run publish
— clean / build / publish
Set Package Data
Reference the npm Docs for the full list
// package.json
{
// ..
"name": "name",
"description": "description",
"keywords": ["keyword"],
"author": "author",
"license": "license",
"repository": {
"type": "git",
"url": "git+https://github.com/username/project-name.git"
},
"bugs": {
"url": "https://github.com/username/project-name/issues"
},
"homepage": "https://github.com/username/project-name#readme"
}
Subpath Exports
Modules can be exported from files other than src/index.ts
// package.json
// Requires Node.js >=12
{
// ..
"tsup": {
// Add a new entry point
"entry": ["src/index.ts", "src/nested/index.ts"]
},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
// Add subpath export as relative paths
"./nested": {
"import": "./dist/nested/index.js",
"require": "./dist/nested/index.cjs"
}
}
}