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

Include examples for where to put options #165

Merged
merged 1 commit into from
Jul 19, 2017
Merged
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
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var app = new EmberApp({
### Options

There are a few different options that may be provided to ember-cli-babel. These options
are typically set in an apps `ember-cli-build.js` file, or in an addons `index.js`.
are typically set in an apps `ember-cli-build.js` file, or in an addon or engine's `index.js`.

```ts
type BabelPlugin = string | [string, any] | [any, any];
Expand Down Expand Up @@ -91,6 +91,39 @@ interface EmberCLIBabelConfig {
}
```

The exact location you specify these options varies depending on the type of project you're working on. As a concrete example, to add `babel-plugin-transform-object-rest-spread` so that your project can use object rest/spread syntax, you would do something like this in an app:

```js
// ember-cli-build.js
var app = new EmberApp(defaults, {
babel: {
plugins: ['transform-object-rest-spread']
}
});
```

In an engine:
```js
// index.js
module.exports = EngineAddon.extend({
babel: {
plugins: ['transform-object-rest-spread']
}
});
```

In an addon:
```js
// index.js
module.exports = {
options: {
babel: {
plugins: ['transform-object-rest-spread']
}
}
};
```

#### Polyfill

Babel comes with a polyfill that includes a custom [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js)
Expand Down Expand Up @@ -160,24 +193,6 @@ You can add custom plugins to be used during transpilation of the `addon/` or `a
trees by ensuring that your addon's `options.babel` is properly populated (as mentioned above in the
`Options` section).

For example, to add `babel-plugin-transform-object-rest-spread` so that your addon can use object
rest/spread you would do something like this:

```js
module.exports = {
name: 'my-special-addon',

init() {
this._super && this._super.init.apply(this, arguments);

this.options = this.options || {};
this.options.babel = this.options.babel || {};
this.options.babel.plugins = this.options.babel.plugins || [];
this.options.babel.plugins.push('transform-object-rest-spread');
};
}
```

#### Additional Trees

For addons which want additional customizations, they are able to interact with
Expand Down