运行 来自 package.json 的打字稿文件?
Run a typescript file from package.json?
我有一个 TypeScript 项目,只有一个 JavaScript 文件 testrunner.js
我也想将其转换为 TS。
我目前 运行 使用 package.json
脚本
测试 运行 纱线
"test": "node testrunner"
当我将测试运行ner 文件转换为 ts 时,我将 package.json
脚本更改如下
"test": "tsc testrunner"
我遇到两个不确定如何解决的问题:
tsc
的命令行执行似乎没有获取 tsconfig.json 中的 compilerOptions
。有可能拿起这些吗?我尝试使用 project
选项,但收到一条消息“选项 'project' 不能与命令行上的源文件混合”
- TSC输出一个JS文件。是否可以在不输出 JS 文件的情况下让 TSC 编译和运行 测试运行ner?
你应该 运行 ts-node in script mode.
ts-node cli 选项
ts-node
支持 --print
(-p
)、--eval
(-e
)、--require
(-r
) 和--interactive
(-i
) 类似于 node.js CLI options.
-s, --script-mode
相对于传递脚本的目录而不是当前目录解析配置。更改 --dir
的默认值
例如
ts-node --script-mode file.js
作为 package.json
的脚本
"test": "ts-node --script-mode testrunner.ts"
我有一个 TypeScript 项目,只有一个 JavaScript 文件 testrunner.js
我也想将其转换为 TS。
我目前 运行 使用 package.json
脚本
"test": "node testrunner"
当我将测试运行ner 文件转换为 ts 时,我将 package.json
脚本更改如下
"test": "tsc testrunner"
我遇到两个不确定如何解决的问题:
tsc
的命令行执行似乎没有获取 tsconfig.json 中的compilerOptions
。有可能拿起这些吗?我尝试使用project
选项,但收到一条消息“选项 'project' 不能与命令行上的源文件混合”- TSC输出一个JS文件。是否可以在不输出 JS 文件的情况下让 TSC 编译和运行 测试运行ner?
你应该 运行 ts-node in script mode.
ts-node cli 选项
ts-node
支持 --print
(-p
)、--eval
(-e
)、--require
(-r
) 和--interactive
(-i
) 类似于 node.js CLI options.
-s, --script-mode
相对于传递脚本的目录而不是当前目录解析配置。更改--dir
的默认值
例如
ts-node --script-mode file.js
作为 package.json
"test": "ts-node --script-mode testrunner.ts"