Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Executes .js files with node + babel

License

NotificationsYou must be signed in to change notification settings

ikatun/nnode

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, onlynicer.

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

TheWhy not babel-node section:

  • 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

Included withnnode are:

  • @babel/core
  • @babel/preset-env
  • @babel/preset-flow
  • @babel/plugin-proposal-class-properties
  • @babel/plugin-proposal-decorators
  • @babel/register
  • @babel/preset-typescript

TheTranspilation section:

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.

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp