Skip to content

Commit

Permalink
Respect babel sourceMaps option
Browse files Browse the repository at this point in the history
  • Loading branch information
dwickern committed Jun 19, 2017
1 parent 90cde9e commit 8119645
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
33 changes: 25 additions & 8 deletions README.md
Expand Up @@ -20,7 +20,7 @@ target browsers (as specified in `config/targets.js` in ember-cli >= 2.13). Runn
through the transpiler shouldn't change the code at all (likely just a format change if it does).

If you need to customize the way that `babel-preset-env` configures the plugins that transform your code,
you can do it by passing in any of the options found [here](https://github.com/babel/babel-preset-env#options).
you can do it by passing in any of the options found [here](https://github.com/babel/babel-preset-env#options).
*Note: `.babelrc` files are ignored by default.*

Example (configuring babel directly):
Expand Down Expand Up @@ -75,9 +75,10 @@ interface EmberCLIBabelConfig {
include?: string[];
exclude?: string[];
useBuiltIns?: boolean;
sourceMaps?: boolean | "inline" | "both";
plugins?: BabelPlugin[];
};

/**
Configuration options for ember-cli-babel itself.
*/
Expand Down Expand Up @@ -107,6 +108,22 @@ var app = new EmberApp(defaults, {
});
```

#### Enabling Source Maps

Babel generated source maps will enable you to debug your original ES6 source code. This is disabled by default because it will slow down compilation times.

To enable it, pass `sourceMaps: 'inline'` in your `babel` options.

```js
// ember-cli-build.js

var app = new EmberApp(defaults, {
babel: {
sourceMaps: 'inline'
}
});
```

#### Modules

Older versions of Ember CLI (`< 2.12`) use its own ES6 module transpiler. Because of that, this plugin disables Babel
Expand Down Expand Up @@ -171,18 +188,18 @@ interface EmberCLIBabel {
Used to generate the options that will ultimately be passed to babel itself.
*/
buildBabelOptions(config?: EmberCLIBabelConfig): Opaque;

/**
Supports easier transpilation of non-standard input paths (e.g. to transpile
a non-addon NPM dependency) while still leveraging the logic within
Supports easier transpilation of non-standard input paths (e.g. to transpile
a non-addon NPM dependency) while still leveraging the logic within
ember-cli-babel for transpiling (e.g. targets, preset-env config, etc).
*/
transpileTree(inputTree: BroccoliTree, config?: EmberCLIBabelConfig): BroccoliTree;

/**
Used to determine if a given plugin is required by the current target configuration.
Does not take `includes` / `excludes` into account.
See https://github.com/babel/babel-preset-env/blob/master/data/plugins.json for the list
of known plugins.
*/
Expand Down Expand Up @@ -217,7 +234,7 @@ let transpiledCustomTree = babelAddon.transpileTree(someCustomTree);

In order to allow apps and addons to easily provide good development mode ergonomics (assertions, deprecations, etc) but
still perform well in production mode ember-cli-babel automatically manages stripping / removing certain debug
statements. This concept was originally proposed in [ember-cli/rfcs#50](https://github.com/ember-cli/rfcs/pull/50),
statements. This concept was originally proposed in [ember-cli/rfcs#50](https://github.com/ember-cli/rfcs/pull/50),
but has been slightly modified during implementation (after researching what works well and what does not).

#### Debug Macros
Expand Down
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -192,8 +192,14 @@ module.exports = {

let providedAnnotation = config['ember-cli-babel'] && config['ember-cli-babel'].annotation;

let sourceMaps = false;
if (config.babel && 'sourceMaps' in config.babel) {
sourceMaps = config.babel.sourceMaps;
}

let options = {
annotation: providedAnnotation || `Babel: ${this._parentName()}`
annotation: providedAnnotation || `Babel: ${this._parentName()}`,
sourceMaps
};

let userPlugins = addonProvidedConfig.plugins;
Expand Down
11 changes: 11 additions & 0 deletions node-tests/addon-test.js
Expand Up @@ -532,6 +532,17 @@ describe('ember-cli-babel', function() {
expect(result.annotation).to.equal('Hello World!');
});

it('uses provided sourceMaps if specified', function() {
let options = {
babel: {
sourceMaps: 'inline'
}
};

let result = this.addon.buildBabelOptions(options);
expect(result.sourceMaps).to.equal('inline');
});

it('does not include all provided options', function() {
let babelOptions = { blah: true };
let options = {
Expand Down

0 comments on commit 8119645

Please sign in to comment.