-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1042 from embroider-build/optimize-ember-cli-babel2
Fix ember-cli-babel optimization
- Loading branch information
Showing
3 changed files
with
41 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import writeFile from 'broccoli-file-creator'; | ||
import V1Addon from '../v1-addon'; | ||
|
||
// Because almost every addon depends on ember-cli-babel, and because ember-cli | ||
// instantiates a separate instance of Addon per consumer, approximately *half* | ||
// of all Addon instances in a typical app will be copies of ember-cli-babel. | ||
// | ||
// Under embroider, *all* of them should be contributing no files to the build. | ||
export default class EmberCliBabel extends V1Addon { | ||
// this ensures we don't bother smooshing together a large number of useless | ||
// copies of the addon. | ||
hasAnyTrees() { | ||
return false; | ||
} | ||
|
||
// and the one copy that we do emit should just be an empty valid package. We | ||
// don't want the babel helpers it emits, they're not even used under | ||
// Embroider anyway. | ||
get v2Tree() { | ||
return writeFile('package.json', JSON.stringify(this.newPackageJSON, null, 2)); | ||
// the only copy of ember-cli-babel that might need to do something is the | ||
// first one that wants to emit babel polyfills. No other copy is allowed to | ||
// emit anything into the build. | ||
reduceInstances(copies: EmberCliBabel[]): EmberCliBabel[] { | ||
let polyfillCopy = copies.find(c => { | ||
let instance = c.addonInstance as any; | ||
return typeof instance._shouldIncludePolyfill === 'function' && instance._shouldIncludePolyfill(); | ||
}); | ||
if (polyfillCopy) { | ||
return [polyfillCopy]; | ||
} else { | ||
return []; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters