Package Exports
- tsup
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tsup) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
tsup
Bundle your TypeScript library with no config, powered by esbuild.
What can it bundle?
Anything that's supported by Node.js natively, namely .js, .json, .mjs. And TypeScript .ts, .tsx.
This project is designed for bundling Node.js libraries.
Install
Install it locally in your project folder:
npm i tsup -D
# Or Yarn
yarn add tsup --devYou can also install it globally but it's not recommended.
Usage
Bundle files
tsup [...files]Files are written into ./dist.
You can bundle multiple files in one go:
tsup src/index.ts src/cli.tsCode splitting is enabled by default and supported in cjs and esm format.
Excluding packages
By default tsup bundles all import-ed modules but dependencies in your packages.json are always excluded, you can also use --external <module> flag to mark other packages as external.
Generate declaration file
tsup index.ts --dtsThis will emit ./dist/index.js and ./dist/index.d.ts.
Bundle formats
Supported format: esm, cjs, (default) and iife.
You can bundle in multiple formats in one go:
tsup src/index.ts --format esm,cjs,iifeThat will output files in following folder structure:
dist
├── index.mjs # esm
├── index.global.js # iife
└── index.js # cjsIf the type field in your package.json is set to module, the filenames will be slightly different:
dist
├── index.js # esm
├── index.global.js # iife
└── index.cjs # cjsRead more about esm support in Node.js.
If you don't want to extensions like .mjs or .cjs, e.g. you want your library to be used in a bundler (environment) that doesn't support those, you can enable --legacy-output flag:
tsup src/index.ts --format esm,cjs,iife --legacy-output..which outputs to:
dist
├── esm
│ └── index.js
├── iife
│ └── index.js
└── index.jsES5 support
You can use --target es5 or "target": "es5" in tsconfig.json to compile the code down to es5, it's processed by buble. Some features are NOT supported by this target, namely: for .. of.
Watch mode
tsup src/index.ts --watchWhat about type checking?
esbuild is fast because it doesn't perform any type checking, you already get type checking from your IDE like VS Code or WebStorm.
Additionally, if you want type checking at build time, you can enable --dts, which will run a real TypeScript compiler to generate declaration file so you get type checking as well.
For more details:
tsup --helpLicense
MIT © EGOIST (Kevin Titor)