cosmosb cosmosb - 5 months ago 68
Node.js Question

How to use babel-runtime in Babel 6?

I'm trying to create npm module and I can't find single instruction on official babeljs website. How do you use babel-runtime package? From name I'm guessing it should be placed in "dependencies" section of package.json, right?

Absolutely no information here: https://github.com/babel/babel/tree/master/packages/babel-runtime

Found one example here: https://strongloop.com/strongblog/javascript-babel-future/ but when I run "babel -h" it doesn't list --optional as a valid parameter.

Answer

The runtime is optional, but like everything else in Babel 6, it is primarily enabled by adding a plugin. In this case, you need http://babeljs.io/docs/plugins/transform-runtime/

plugins: ["transform-runtime"]
  • babel-runtime is a package that contains a polyfill and many other things that Babel can reference. You'd install it in your app with npm install babel-runtime
  • transform-runtime is a Babel plugin to process your source code and inject import foo from "babel-runtime" statements so that babel-runtime is actually used. You'd also install this with npm install babel-plugin-transform-runtime.
Comments