DEV Community

Discussion on: A Nice TypeScript Buildchain

Collapse
prodigalknight profile image
RevanProdigalKnight • Edited on

Actually, it's even easier - the Typescript compiler has an option for converting import statements to require statements (and export statements to module.exports) built in. You can simply put "module": "CommonJS" into your tsconfig.json file, and you can still stick to using just the Typescript compiler to generate ES6 code that will run in Node.js.

Collapse
hjfitz profile image
Harry Author

That's awesome, I really didn't know that!

I like being able to polyfill though, which was more the point of this. Writing clean async/await code and then compiling to an older version of node is great. I have to support node 6 in my day job.

Collapse
zeerorg profile image
Rishabh Gupta

Setting module to CommonJs will compile async await to ES6, the same way Babel does.
Buy this guide is pretty useful considering we can add more functionality with Babel and gulp later on.