Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] browserPolyfill option #24

Merged
merged 3 commits into from
Jun 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ var scriptTree = esTranspiler(inputTree, {
```

`exportModuleMetadata` is an option that can be used to write a JSON file to the output tree that gives you metadata about the tree's imports and exports.

## Polyfill

In order to use some of the ES6 features you must include the Babel [polyfill](http://babeljs.io/docs/usage/polyfill/#usage-in-browser).

You don't always need this, review which features need the polyfill here: [ES6 Features](https://babeljs.io/docs/learn-es6).

```js
var esTranspiler = require('broccoli-babel-transpiler');
var scriptTree = esTranspiler(inputTree, { browserPolyfill: true });
```
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var clone = require('clone');
var path = require('path');
var fs = require('fs');
var stringify = require('json-stable-stringify');
var mergeTrees = require('broccoli-merge-trees');
var funnel = require('broccoli-funnel');

function getExtensionsRegex(extensions) {
return extensions.map(function(extension) {
Expand Down Expand Up @@ -39,6 +41,18 @@ function Babel(inputTree, options) {
// delete it from the options hash
delete this.options.exportModuleMetadata;
}

if (this.options.browserPolyfill) {
delete this.options.browserPolyfill;

var babelCorePath = require.resolve('babel-core');
babelCorePath = babelCorePath.replace(/\/babel-core\/.*$/, '/babel-core');

var polyfill = funnel(babelCorePath, { files: ['browser-polyfill.js'] });
this.inputTree = mergeTrees([polyfill, inputTree]);
} else {
this.inputTree = inputTree;
}
}

Babel.prototype = Object.create(Filter.prototype);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"babel-core": "^5.0.0",
"json-stable-stringify": "^1.0.0",
"cauliflower-filter": "^1.0.4",
"broccoli-funnel": "^0.2.3",
"broccoli-merge-trees": "^0.2.1",
"clone": "^0.2.0"
},
"devDependencies": {
Expand Down