lask
is a build tool for TypeScript libraries. It uses esbuild to build and bundle code and tsc to generate types. It is pretty opinionated. You might use it as a reference for building your own mini build tool.
npm install lask --dev
or
yarn add lask --dev
- Install
lask
to your project'sdevDependencies
. - Run
yarn lask
to build your project, oryarn lask -d
to start your project in development mode.
If you like what you get, add lask
to your package.json
's scripts
section:
{
"scripts": {
"build": "lask",
"dev": "lask -d",
"test": "lask test"
}
}
By default, lask
expects your root directory to have:
- source code in the
src
directory - output in the
dist
directory - a
tsconfig.json
file in the root directory - a
tsconfig.dev.json
file in the root directory - a
tsconfig.build.json
file in the root directory - a
package.json
with the following fields:
You can configure lask
by creating a lask.config.json
(sorry) in your project's root directory.
This config can include some or all of the following properties:
interface Options {
isDev: boolean
isNode: boolean
entryPoints: string[]
outDir: string
clean: boolean
external: {
dependencies: boolean
devDependencies: boolean
peerDependencies: boolean
}
target: string
format: 'esm' | 'cjs' | ('esm' | 'cjs')[]
devFormat: 'esm' | 'cjs'
devConfig: string
buildConfig: string
define: { [key: string]: string }
calculateSize: boolean
}
For example:
{
"isNode": true,
"entryPoints": ["./src/index.ts"],
"clean": true,
"outDir": "dist",
"external": {
"dependencies": true,
"devDependencies": true,
"peerDependencies": true
},
"devConfig": "tsconfig.dev.json",
"buildConfig": "tsconfig.build.json",
"format": ["cjs", "esm"],
"calculateSize": true
}
Whether to build / develop for node, rather than neutral JavaScript.
Where to place the output files. By default, this is dist
. This means that your package.json
should look like:
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"source": "./src/index.ts",
If you set a different value for outDir
, be sure to also update those fields in your package.json
.
The location of the tsconfig
file to use for lask
. Defaults to tsconfig.build.json
.
The location of the tsconfig
file to use for lask -d
. Defaults to tsconfig.dev.json
.
Whether to remove the dist
folder before building. Defaults to true
.
By default, all three options here are set to true
, which means that lask
will exclude all dependencies / peerDependencies / devDependencies from the bundled output.
Passed to esbuild's define
option. By default, define
is set to either { "process.env.NODE_ENV": "production" }
or { "process.env.NODE_ENV": "development" }
depending on the isDev
option.
Whether to build to "esm"
, "cjs"
, or ["cjs", "esm"]
. Defaults to ["cjs", "esm"]
.
Whether to calculate the size of the output for each format. Defaults to true
.
Be sure that the outDir
in your tsconfig.json
(or tsconfig.build.json
, etc.) is pointing to the correct folder. If you're outputting types to ./dist
but your tsconfig.json
has an outDir
set to ./dist/types
, the conversion won't work.
This project is MIT licensed.