简体   繁体   中英

Equivalent of Babel plugin for Typescript?

Using the Typescript compiler API, I can do code transformations in my own scripts. But seeing how Typescript doesn't have a plugin/extension architecture, I can't find a way to integrate this into my build pipeline.

With Babel, you can integrate custom code transformation easily by packaging your code in a plugin and loading that plugin using the .babelrc file.

So I'm asking if Typescript is providing anything like the Babel plugin system where you can write your visitor-pattern-based transformations and plug it straight into the default compiler?

Yes it has. This is the official documentation I recommend you to start with:

First one explain how to use the compiler, transverse in particular this example https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#user-content-creating-and-printing-a-typescript-ast

The other link introduce to the Language Service to create plugins (more oriented to text editors / IDEs)

If tose are too hard to grasp perhaps this si of help too: https://github.com/cancerberoSgx/typescript-plugins-of-mine (collection of small examples & utlities & tutorials on ts plugins, compiLer API, utilities and links to get started),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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