@viocha/tsr
v0.3.4
Published
A simple TypeScript Node.js runner
Readme
tsr — TypeScript Runner
Run TypeScript files instantly.
A CLI tool for compiling and running.tsfiles with zero config, powered by esbuild and Rollup.
✨ 特性 Features
- 🚀 快速执行:一条命令立即运行
.ts文件 - 🔧 无需配置:零配置使用,适合脚本调试和原型开发
- 🧱 构建支持:可构建为独立 ES 模块输出
- 📦 支持 CommonJS、JSON 和 NODE_PATH
- 🧹 自动清理:执行后的临时文件自动删除
📦 安装 Installation
npm install -g @viocha/tsr或本地使用:
npm install @viocha/tsr --save-dev🚀 快速开始 Quick Start
运行 TypeScript 文件
tsr hello.ts或者
tsr run hello.ts支持传参:
tsr run hello.ts arg1 arg2仅构建,不运行
tsr build hello.ts输出文件默认为 out/hello.js,也可自定义路径:
tsr build hello.ts -o dist/output.js⚙️ 可选参数 Options
tsr build
| 参数 | 描述 |
|-------------------------|------------------------|
| -o, --out <path> | 自定义输出文件路径 |
| -e, --external <deps> | 指定外部依赖(逗号分隔),不会打包进输出文件 |
示例:
tsr build src/index.ts -o dist/index.js -e lodash,react📁 示例文件 Example
// hello.ts
console.log('Hello,', process.argv[2] || 'World!');tsr run hello.ts TypeScript
# 输出: Hello, Typescript!🔍 实现原理 Behind the Scenes
- 使用 esbuild 快速编译 TypeScript 为 JavaScript
- 使用 Rollup 优化构建结果,支持 CommonJS/JSON
- 使用
tmp创建临时执行文件,运行完毕后自动清除 - 自动解析
NODE_PATH中的模块路径
