Name: ts-babel-node
Owner: looker
Description: Enables Babel compilation of TypeScript compilation as a Node wrapper.
Forked from: danielmoore/ts-babel-node
Created: 2018-01-06 03:44:05.0
Updated: 2018-01-06 03:44:07.0
Pushed: 2018-01-06 03:47:24.0
Size: 39
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This package enables Babel compilation of TypeScript compilation output through a registration function and a Node binary proxy.
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
.
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.
m install --global ts-babel-node typescript@1.8
-babel-node my-file.ts
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.
m install --save-dev ts-babel-node typescript@1.8
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 env
preset in your config (or don't, if you don't want it).
ts-babel-node
exposes two APIs. The first is a wrapper around the ts-node
API.
node this-file.js
ire('ts-babel-node').register(tsNodeOpts, babelOpts); // both opts are optional
r
ire('ts-babel-node/register');
You can also use this with the --require
option on node
.
de --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
ire('ts-babel-node').registerBabel(babelOpts); // babelOpts is optional
r
ire('ts-babel-node/register-babel');
cha --require ts-babel-node/register [...args]
-babel-node node_modules/.bin/tape [...args]
In your gulpfile.ts
(note, .ts
, not .js
):
rt 'ts-babel-node/register-babel';
..
Then use gulp
normally. Keep in mind that the babel transpiler won't be active in your gulpfile.ts
, but will be running in all your imports.