Skip to content

Commit

Permalink
add emberPlugins as the property in index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
suchitadoshi1987 committed Dec 8, 2020
1 parent ae129c8 commit a5dfa5a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ module.exports = function(defaults) {
```
### Babel config usage

If you want to use the existing babel config from your project instead of the auto-generated one from this addon, then you would need to *opt-in* by passing the config `useBabelConfig: true` in your `ember-cli-build.js` file.
If you want to use the existing babel config from your project instead of the auto-generated one from this addon, then you would need to *opt-in* by passing the config `useBabelConfig: true` as a child property of `ember-cli-babel` in your `ember-cli-build.js` file.

*Note: If you are using this option, then you have to make sure that you are adding all of the required plugins required for Ember to transpile correctly.*

Expand All @@ -304,8 +304,8 @@ Example usage:
//ember-cli-build.js

let app = new EmberAddon(defaults, {
useBabelConfig: true,
"ember-cli-babel": {
useBabelConfig: true,
// ember-cli-babel related options
},
});
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const path = require('path');
const fs = require('fs');
const getBabelOptions = require('./lib/get-babel-options');
const findApp = require('./lib/find-app');
const emberPlugins = require('./lib/ember-plugins');

const APP_BABEL_RUNTIME_VERSION = new WeakMap();

Expand All @@ -32,6 +33,7 @@ let count = 0;
module.exports = {
name: 'ember-cli-babel',
configKey: 'ember-cli-babel',
emberPlugins,

init() {
this._super.init && this._super.init.apply(this, arguments);
Expand Down Expand Up @@ -108,7 +110,9 @@ module.exports = {
const babelConfigFile = ROOT_CONFIG_FILENAMES.find((fileName) =>
fs.existsSync(path.resolve(this.parent.root, fileName))
);
const shouldUseBabelConfigFile = config.useBabelConfig && babelConfigFile;

const customAddonConfig = config['ember-cli-babel'];
const shouldUseBabelConfigFile = customAddonConfig && customAddonConfig.useBabelConfig && babelConfigFile;

if (shouldUseBabelConfigFile) {
options = Object.assign({}, options, {
Expand Down
8 changes: 6 additions & 2 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,9 @@ describe('babel config file', function() {
project.initializeAddons();

self.addon = project.addons.find(a => { return a.name === 'ember-cli-babel'; });
self.addon.parent.options = { useBabelConfig: true };
self.addon.parent.options = {
"ember-cli-babel": { useBabelConfig: true },
};

input = yield createTempDir();
});
Expand Down Expand Up @@ -1694,7 +1696,9 @@ describe('babel config file', function() {
{ noInterop: true },
]`);

this.addon.parent.options = { useBabelConfig: false };
this.addon.parent.options = {
"ember-cli-babel": { useBabelConfig: false },
};
input.write({
"foo.js": `export default {};`,
});
Expand Down

0 comments on commit a5dfa5a

Please sign in to comment.