我很难找到答案。使用普通的 Node.JS,您可以使用 node path/to/file.js
运行任何 js 文件,使用 CoffeeScript 它是 coffee hello.coffee
并且 ES6 有 babel-node hello.js
。我如何对 Typescript 做同样的事情?
我的项目有一个 tsconfig.json
被 Webpack/ts-loader 用来为浏览器构建一个漂亮的小包。不过,在此之前我需要从控制台运行构建步骤,这将使用项目中使用的一些 .ts
文件来生成模式,但我似乎无法运行单个 Typescript 文件而不编译整个项目。
原文由 Gunchars 发布,翻译遵循 CC BY-SA 4.0 许可协议
You can leave
tsc
running in watch mode usingtsc -w -p .
and it will generate.js
files for you in a live fashion, so you can runnode foo.js
和平常一样TS 节点
有 ts-node : https://github.com/TypeStrong/ts-node 将即时编译代码并通过节点运行它🌹