Refreshingly simple CLI for TypeScript packages.
npm install @mapbox/typehead!logo
Typehead is a thin wrapper around ESBuild that makes it refreshingly simple to develop NPM packages using TypeScript.
š¦ npm install --save-dev @mapbox/typehead typescript
In your package.json:
``json`
{
"main": "dist/index.js",
"module": "dist/index-esm.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "typehead build",
"watch": "typehead build --watch",
"serve": "typehead serve"
}
}
Typehead will not check types or generate declaration files. While this seems initially counter-intuitive, this operation is costly and usually covered by IDE tools (VSCode) and CI (using tsc).
We recommend setting this up with tsc, which is included with TypeScript.
Here's an example that builds types before publishing to NPM:
tsconfig.types.json:
`json`
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./dist"
},
"include": ["src/", "src//"]
}
package.json:
`json`
{
"scripts": {
"types": "tsc -p tsconfig.types.json",
"prepare": "npm run types && npm run build"
}
}
typehead build will automatically set the entry point to src/index. You can use either .ts, .tsx, .jsx, or .js files. We heavily recommend the use of TypeScript for all packages.
Output files will live in dist/:
This behavior is configurable (see below).
- A development CSM build index-development.js that is not minified.index.js
- A production CSM build that is minified.index-esm.js
- A production ESM build that is not minified.
If globalName is specified in customization, then a fourth build will be created with that name.
- A production IIFE build {globalName}.js that is minified and includes all dependencies statically.
The IIFE build is suitable for distribution on CDNs and UNPKG.
package.json:
``
{
"unpkg": "dist/{globalName}.js"
}
typehead serve will start a web server for the web directory (if present).
Inside web, web/index.{js,jsx,ts,tsx} will be bundled by ESBuild for browser use. From this file, you can import your main module from ../src and do things like demos, benchmarking, etc...
The bundle will be accessible from the web server at /index-bundle.js. Make sure to use type="module" in your