@ts-tools/node

5.0.2 • Public • Published

@ts-tools/node

npm version

TypeScript support for Node.js.

This package installs a require extension, adding support for running .ts and .tsx files directly from source.

Features:

  • Fast! Uses ts.transpileModule. Leaves type checking to other flows.
  • Uses persistent disk caching (./node_modules/.cache/ts-<module>-<target>). Second run will not re-transpile a file if not changed.
  • Built-in support for source-maps, powered by source-map-support.
  • Node 8+ friendly default compiler options.

Getting started

Install the library as a dev dependency in an existing TypeScript project:

npm i @ts-tools/node --save-dev

Usage with Node.js:

node -r @ts-tools/node/r ./my-script.ts

Usage with Mocha:

mocha -r @ts-tools/node/r "./test/**/*.test.ts?(x)" --watch-extensions ts,tsx

OR, create a .mocharc.js file with:

module.exports = {
  require: ['@ts-tools/node/r'],
  extension: ['js', 'json', 'ts', 'tsx'],
};

Usage with Visual Studio Code:

// in .vscode/launch.json, under "configurations"
{
  "type": "node",
  "request": "launch",
  "name": "Launch Program",
  "runtimeArgs": ["-r", "@ts-tools/node/r"],
  "args": ["${workspaceFolder}/src/my-script.ts"]
}

Similar projects

ts-node - a much more complete solution. It includes a ts-node cli/repl, and require hook registration.

License

MIT

Dependents (7)

Package Sidebar

Install

npm i @ts-tools/node

Weekly Downloads

1,318

Version

5.0.2

License

MIT

Unpacked Size

23.1 kB

Total Files

18

Last publish

Collaborators

  • avi.vahl