Repository navigation
Add ability to deduplicate babel helpers. - #251
Conversation
rwjblue
left a comment
There was a problem hiding this comment.
Some fundamental issues here:
- How do we deal with helper incompatibility between versions (both major versions and minor/patch)?
eb0b90d to
95283a0
Compare
|
Alright, I think this is ready for another round of review. Added tests and made sure everything actually working the way it should be! |
aa695e2 to
468c45a
Compare
468c45a to
9291be1
Compare
6eddb03 to
8140161
Compare
| }, | ||
|
|
||
| _getHostOptions() { | ||
| let host = this._findHost(); |
There was a problem hiding this comment.
The EngineAddon wrapper in ember-engines overrides _findHost to point to the first lazy-loading engine it comes to rather than the root app. We may need to explicitly traverse the parent chain ourselves here.
There was a problem hiding this comment.
Actually, since this only ever needs the host options when this.parent === this.project, I think we can just access this.app directly and not need to bother with findHost.
| [ | ||
| require.resolve('@babel/plugin-transform-runtime'), | ||
| { | ||
| version: this._getHelperVersion(), |
There was a problem hiding this comment.
I see how they're using version in the implementation, but I can't find any documentation for it on the plugin page. I don't imagine that's intended to be a "secret" option, but have you seen anything indicating it's public?
There was a problem hiding this comment.
I have not, but it's definitely needed to actually include decorator helpers or anything more recent than 7.0.0-0, so I can't imagine it's not public? Does seem very strange to me though
1be3132 to
723a038
Compare
This PR adds the `includeExternalHelpers` config option which allows users to explicitly opt into using externalized helpers for transpiled code. In large apps this can help with app size, especially in apps which are making heavy usage of new ES features like native classes and decorators. This option is a _global_ option, meaning it _must_ be configured in the root application. The reason for this is because there must be one canonical source of truth for which version of helpers are being used, and whether or not helpers are being used at all. If one addon decides to use helpers, the app must include them, and they must be the right version. By default, ec-babel will check the dependency tree to see if there are any addons which exist which will incur heavy expenses, such as decorators. If so, it'll externalize helpers by default. Eventually this behavior will be unnecessary due to treeshaking. The current setup will _only_ support babel 7 helpers. This can be expanded upon in the future, but the complexity of doing so makes it beyond the scope of the initial work here.
723a038 to
d8c2b1b
Compare
This PR sets up the groundwork for allowing Ember apps to externalize Babel helpers, reducing the amount of code shipped to the client by deduplicating common code included by Babel.
Externalized helpers represent a unique problem, because in order to truly deduplicate all helpers, the app and all of its addons need to have a shared contract for which helpers will be included in the global namespaces and which will not. Currently we don't have a method to coalesce configurations from many addons, so the current implementation only works with a single, global, app-wide configuration. Eventually this could be set to reasonable defaults, but now it is left off.
Still WIP, definitely needs testing and tests.