Compile and run TypeScript in Node with source map support in about 50 lines of code.
Directly run a TypeScript file right now without installing anything but Node:
npx @lib/run script.ts
Or install:
npm install --save-dev @lib/run
Then:
npx run script.ts
Or within a package.json
script:
run script.ts
The option -p
will require()
a JS file before loading the TypeScript compiler. It can be given multiple times:
npx run -p ./preload-1.js -p ./preload-2.js script.ts
0BSD, which means use as you wish and no need to mention this project or its author. Consider it public domain in practice.