bob-ts
Transpile your TypeScript applications quickly using esbuild + rollup.
Install
pnpm add -D bob-ts esbuild
yarn add -D bob-ts esbuild
npm install -D bob-ts esbuild
Usage
By default bob-ts
is ESM first, but you can change it to be either CJS with: -f cjs
or -f interop
to transpile for both CommonJS & ESM.
If you have "type": "module"
in your package.json
, ESM
will be outputted with the extension .mjs
and CJS
as .js
.
If you don't have "type": "module"
in your package.json
, ESM
will be outputted with the extension .js
and CJS
as .cjs
Build
Usage: bob-ts [options]
Options:
-d, --dir <directory> Custom output dir (default: "dist")
-i, --input <patterns...> Input patterns (default: ".")
-f, --format <format> Format, it can be 'cjs', 'esm' or 'interop' (default: "esm")
--cwd <dir> Custom target directory (default: "/home/pablosz/learner-model-gql/gateway")
--no-clean No clean output dir (default: true)
-h, --help display help for **command**
This will transpile all your src
folder, and its structure will be kept as is in the dist
folder
{
"scripts": {
"prepare": "bob-ts -i src"
}
}
Development / Watch Mode
Usage: bob-ts-watch [options]
Options:
-d, --dir <directory> Custom output dir (default: "dist")
-i, --input <patterns...> Input patterns (default: ".")
-f, --format <format> Format, it can be 'cjs', 'esm' or 'interop' (default: "esm")
--no-clean No clean output dir (default: true)
--cwd <dir> Custom target directory (default: "/home/pablosz/learner-model-gql/gateway")
-c, --command <cmd> Execute script after successful JS build
-h, --help display help for command
{
"scripts": {
"dev": "bob-ts-watch -i src -c \"node dist/index.mjs\""
}
}
Usage with Testing
Mocha
pnpm add -D mocha nyc @istanbuljs/esm-loader-hook
yarn add -D mocha @istanbuljs/esm-loader-hook
npm install -D mocha @istanbuljs/esm-loader-hook
ESM
{
"scripts": {
"dev": "bob-ts-watch -c \"node/dist/src/index.mjs\"",
"start": "bob-ts && node/dist/src/index.mjs",
"test": "bob-ts && nyc mocha --experimental-loader=@istanbuljs/esm-loader-hook --enable-source-maps dist/test",
"test:watch": "bob-ts-watch -c \"nyc mocha --experimental-loader=@istanbuljs/esm-loader-hook --enable-source-maps dist/test\""
}
}
CJS
{
"scripts": {
"dev": "bob-ts-watch -f cjs -c \"node dist/src/index.js\"",
"start": "bob-ts -f cjs && node dist/src/index.js",
"test": "bob-ts -f cjs && nyc mocha dist/test",
"test:watch": "bob-ts-watch -f cjs -c \"nyc moca dist/test\""
}
}
Node Tap
pnpm add -D tap @istanbuljs/esm-loader-hook
yarn add -D tap @istanbuljs/esm-loader-hook
npm install -D tap @istanbuljs/esm-loader-hook
ESM
Assumming that your tests are inside a test
directory
{
"scripts": {
"dev": "bob-ts-watch -c \"node/dist/src/index.mjs\"",
"start": "bob-ts && node/dist/src/index.mjs",
"test": "bob-ts && tap dist/test",
"test:watch": "bob-ts-watch -c \"tap dist/test\""
},
"tap": {
"node-arg": ["--no-warnings", "--experimental-loader", "@istanbuljs/esm-loader-hook"]
}
}
CJS
{
"scripts": {
"dev": "bob-ts-watch -f cjs -c \"node/dist/src/index.js\"",
"start": "bob-ts -f cjs && node/dist/src/index.js",
"test": "bob-ts -f cjs && tap dist/test",
"test:watch": "bob-ts-watch -f cjs -c \"tap dist/test\""
}
}