Files
meteor/packages/babel-compiler
Ben Newman 49a60f155b Support .babelrc presets and plugins.
In addition to package.json files with "babel" sections, BabelCompiler now
supports .babelrc files, though in both cases only the "presets" and
"plugins" fields are respected. If a .babelrc file is found, package.json
files are ignored.

Additional presets and plugins are now *prepended* to the original
babelOptions.{presets,plugins} lists, so that the custom plugins have a
chance to handle syntax differently than babel-preset-meteor would.

The inputFile.getPackageJson method has been replaced by a more general
method, inputFile.findControlFile.

Fixes #6351.
2016-05-20 12:59:08 -04:00
..
2015-07-16 17:41:09 -04:00

Babel is a parser and transpiler for ECMAScript 2015 syntax and beyond, which enables some upcoming JavaScript syntax features to be used in today's browsers and runtimes.

Meteor's Babel support consists of the following core packages:

  • babel-compiler - Exposes the Babel API on the symbol Babel. For example, Babel.compile(source, options).

  • babel-runtime - Meteor versions of the external helpers used by Babel-generated code. Meteor's core packages must run on IE 8 without polyfills, so these helpers cannot assume the existence of Object.defineProperty, Object.freeze, and so on.

Babel API

The babel-compiler package exports the Babel symbol, which exposes functionality provided by the meteor-babel NPM package, which is in turn implmented using the babel-core NPM package. Note that you can only use the babel-compiler package on the server.

Example:

var babelOptions = Babel.getDefaultOptions();

// Modify the default options, if necessary:
babelOptions.whitelist = [
  "es6.blockScoping", // For `let`
  "es6.arrowFunctions" // For `=>`
];

var result = Babel.compile(
  "let square = (x) => x*x;",
  babelOptions
);

// result.code will be something like
// "var square = function (x) {\n  return x * x;\n};"

Use Babel.compile(source) to transpile code using a set of default options that work well for Meteor code.

Resources: