简体   繁体   English

带有require的'ts节点编程用法'('ts-node / register')

[英]ts-node programmatic usage with require('ts-node/register')

ts-node suggests to use require('ts-node/register') . ts-node建议使用require('ts-node/register') And this can be seen in angular2-webpack-starter Protractor configuration . 这可以在angular2-webpack-starter Protractor配置中看到。

What is require('ts-node/register') supposed to do? 什么是require('ts-node/register')应该做什么? Does it patch require to transpile TS files, so a part of Node.js application could be written in TypeScript? 它是否require转换TS文件,因此Node.js应用程序的一部分可以用TypeScript编写?

It does what you think it does. 它做你认为它做的。 require('ts-node/register') is actually the same as: require('ts-node/register')实际上与:

require('./').register({
    lazy: true
})

See examples here: https://github.com/TypeStrong/ts-node/tree/master/register 请参阅此处的示例: https//github.com/TypeStrong/ts-node/tree/master/register

The .register function registers the Typescript compiler for files with .ts and .tsx extension for compilation on the fly. .register函数为Typescript编译器注册扩展名为.ts.tsx文件,以便即时编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM