cosmosb cosmosb - 11 months ago 131
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:

Found one example here: but when I run "babel -h" it doesn't list --optional as a valid parameter.


The runtime is optional, but like everything else in Babel 6, it is primarily enabled by adding a plugin. In this case, you need

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.