- Notifications
You must be signed in to change notification settings - Fork2
Executes .js files with node + babel
License
ikatun/nnode
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
So nice, you'd introduce it to your parents.
nnode
executes .js and .ts files with node + babel.
It works just likenode
, onlyn
icer.
For using thennode
cli, install the package globally:
npm install -g nnode
When using thennode
package asrequire('nnode')
, install the package as a dependency:
npm install nnode --save
run-me.js
importpathfrom'path';constx={this:'this',very:'really'};const{ very}=x;console.log(`Awww, this is${very} nice.`);
If you try runningnode run-me.js
, you'll see:
--SyntaxError: Unexpected token import
That's not very nice, try something nicer, likennode run-me.js
:
--Awww, this is really nice.
You can alsorequire('nnode')
which works just likerequire('babel-register') without needing to setup .babelrc and installing babel presets, plugins and other non-niceties.Useful when running stuff withpm2
ornodemon
.If you're using typescript, you shouldrequire('nnode/ts')
instead
- babel-node requires babel presets, plugins and .babelrc file to be present in the local project
- you don't want to keep finding and installing them one by one every time you want to run something
- sometimes, a combination of plugins and presets or their versions just doesn't work
- this is why nnode depends on them by the exact patch version
- @babel/core
- @babel/preset-env
- @babel/preset-flow
- @babel/plugin-proposal-class-properties
- @babel/plugin-proposal-decorators
- @babel/register
- @babel/preset-typescript
Whennnode
is called with--transpile
flag, it goes into transpilation mode.
This allows us to transpile a directory for older node (v.6.0) which is useful for npm publish.
So, this call:
nnode --transpile
will transpile every .js file within thesrc
directory into thebuild
directory.Build directory and all the subdirectories will be created if necessary.Generated code will be targeted for node version 6.0.