Giter Club home page Giter Club logo

ts-babel-node's Introduction

TypeScript-Babel Node Build Status

This package enables Babel compilation of TypeScript compilation output through a registration function and a Node binary proxy.

Why do I want this?

Because you want ts-node to run async/await code, but TypeScript will only compile async/await to ES6 and Node 5.x doesn't support all of ES6 yet. So you need Babel to bridge that gap.

ts-babel-node wraps ts-node so you can do just that. Run the ts-babel-node executable exactly the same way you'd run ts-node and require ts-babel-node/register instead of ts-node/register.

Installation

Command Line

To use ts-babel-node on the command line, install this package globally. Be sure to include whichever version of TypeScript you want to compile against.

$ npm install --global ts-babel-node [email protected]

$ ts-babel-node my-file.ts

Library

To include ts-babel-node as a register function, install this package as a development dependency. Be sure to include whichever version of TypeScript you want to compile against.

$ npm install --save-dev ts-babel-node [email protected]

Usage

Command Line

Since ts-babel-node is a wrapper around ts-node, anything you can do with ts-node works with ts-babel-node. See ts-node's docs for more details.

To configure babel, you can pass in an options object to the appropriate register function or use a babelrc. All babelrc locations are supported. Note: if you use a babelrc, the default babel configuration provided by ts-babel-node will not be used. Simply include the es2015 preset in your config (or don't, if you don't want it).

Library

ts-babel-node exposes two APIs. The first is a wrapper around the ts-node API.

// $ node this-file.js

require('ts-babel-node').register(tsNodeOpts, babelOpts); // both opts are optional
// Or
require('ts-babel-node/register');

You can also use this with the --require option on node.

$ node --require ts-babel-node/register my-file.ts

The second API only adds the babel-compilation step. This is useful if your code is run from ts-node, as is the case in the gulp scenario.

// $ ts-node this-file.js

require('ts-babel-node').registerBabel(babelOpts); // babelOpts is optional
// Or
require('ts-babel-node/register-babel');

Mocha

$ mocha --require ts-babel-node/register [...args]

Tape

$ ts-babel-node node_modules/.bin/tape [...args]

Gulp

In your gulpfile.ts (note, .ts, not .js):

import 'ts-babel-node/register-babel';
// ...

Then use gulp normally. Keep in mind that the babel traspiler won't be active in your gulpfile.ts, but will be running in all your imports.

ts-babel-node's People

Contributors

danielmoore avatar niieani avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.