跳到主要内容

6.0.0 Released

· 阅读需 6 分钟

NOTE: Not all integrations have been updated yet. This is a very disruptive major so please bear with us as we smooth out the edges.

It’s hard to believe it’s been a year since the Babel project started, but there was a birthday cake, so it must be real!

A whole lot has happened over the last year. We’ve travelled all over the world talking about Babel, and we’ve met some really awesome people along the way.

Babel has spent the last year finding its place in the JavaScript community. In February we decided that Babel wasn’t just going to be a ES6 transpiler. Instead, it needed to become a platform. A suite of tools designed to create the next generation of JavaScript tooling.

When we released Babel 5, it came with a new plugin API that allowed anyone to use the full power of Babel to create tools that plug directly into the transform process. In just a few short months this has blown up into an entire ecosystem of tools.

Developers have built everything from debugging tools, framework optimizations, and minifiers to experimental new syntaxes and systems to enforce complex rules on their codebases. These extensions have proven to be both creative and extremely useful.

People have also built complex tooling on top of Babel internals, like documentationjs which uses Babel’s Babylon parser to replace an existing tool with a much more intelligent version.

But we think we can go even further. Babel should be able to power minifiers, linters, formatters, syntax highlighters, code completion tools, type checkers, codemod tools, and every other tool to be using the same foundation to do their job better than ever before.

So today we’re releasing Babel 6.

This is the most significant update we’ve ever made and enables the project to truly become a platform for the community to build upon.

Modularization

The biggest change you’ll notice is that Babel has been completely restructured to be as modular as possible, and all of the transformers have been rewritten as plugins using the same API that is exposed to everyone.

All of the internals have been pulled out into separate packages as well, each defining a lightweight public API that can be used independently of everything else.

If there’s something you want to build with some Babel internals, you can now just install the package and have full access to them. Inside the packages directory you’ll find all existing packages and plugins.

Opt-in Plugins

Since Babel is focusing on being a platform for JavaScript tooling and not an ES2015 transpiler, we’ve decided to make all of the plugins opt-in. This means when you install Babel it will no longer transpile your ES2015 code by default.

In order to drastically simplify the public API of Babel, each transformer is now completely independent. This means the ‘blacklist’, ‘whitelist’, ‘optional’, ‘nonStandard’, and ‘modules’ options have all been removed, but that doesn’t mean you need to do more work to get Babel to transform your codebase.

Plugin Presets

Since specifying and maintaining dozens of transformers in a config file would be a lot of work, Babel 6 is introducing the concept of Plugin Presets which group together similar plugins for easy consumption.

Shell
$ npm install --save-dev babel-preset-es2015
JavaScript
{
“presets”: [“es2015”]
}

The official presets included today are babel-preset-es2015 and babel-preset-react, but we expect there will be many more in the future.

We also added presets for stages such as babel-preset-stage-0 (used to be stage: 0 in .babelrc in babel 5.x).

Performance Improvements

Performance continues to be one of the top priorities of Babel. Babel 5 changed the transformation and traversal pipeline dramatically to make way for some major performance improvements that have been implemented in Babel 6.

The traversal process is one of biggest chunks of time spent in the Babel pipeline. With any AST-based tool you want to make sure that you traverse the tree as little as possible to keep it fast. Plugins were designed around this so that they could be lightning fast while working with everything else.

Babel 6 implements a new optimization which merges all plugins together into a single traversal. It then manages the traversal process completely so plugins don’t ever have to worry about doing so manually. As a developer you can simply focus on writing your transform, and Babel will handle the rest.

Plugin API

We received a lot of feedback that the plugin API was confusing, so in Babel 6, it’s a bit simpler. Note that this is a breaking change, but it should reduce confusion quite a bit.

Babel 5

JavaScript
export default function({ Plugin, types: t }) {
return new Plugin(‘ast-transform’, {
visitor: {}
});
}

Babel 6

JavaScript
export default function({ types: t }) {
return {
visitor: {}
};
}

Plugin Authors: When updating your plugins, please remember to bump your major versions since this makes Babel 5 and 6 incompatible. Semver is important!

New/Updated Proposals

There are a couple of updated TC39 proposals that have come out. Babel 6 updates to the latest revisions of decorators, class properties, and others.

In Closing

This is a really exciting release for us.

Anyone who's ever been involved with an open source project knows that it's a ton of work, but at the end of the day it's incredibly gratifying to be able to contribute even the tiniest bit back to the community.

Sebastian has been up literally all night to finish all the last minute things needed to launch Babel 6 during his EmberCamp keynote. It's currently 1am for me in San Francisco and I'm writing this blog post as quickly as possible, listening to EDM music to stay awake.

I want to thank everyone who has ever helped out even the littlest bit with Babel. A huge shoutout to Logan Smyth (@loganfsmyth), Henry Zhu (@hzoo), Jesse McCarthy (@jmm), and Denis Pushkarev (@zloirock) for all their hard work managing issues and contributing to Babel.

We’re excited to finally release Babel 6 to the world. As always, we’re committed to pushing Babel to be the best tool it can be, so please keep the GitHub issues and pull requests coming!