Open SaladFork opened 7 years ago
How would you select which ones you expose? Until we have tree shaking in ember-cli I would be against this addition.
Ember composable helpers have a feature where you can select which helpers to expose
https://github.com/DockYard/ember-composable-helpers/blob/master/index.js
@tchak - I apologize for deviating from the subject, but what are you trying to gain from tree-shaking with ember? As I see it,
// from
import { map, invoke } from 'lodash';
// to
import map from 'lodash/map';
import invoke from 'lodash/invoke';
2) The code required for an ember app is already very large and would likely negate any size-reduction via tree-shaking.
@olsonpm some tree shaking can already be done via ember-browserify and broccoli-rollup. For example using ember-date-fns instead of ember-moment can save you quite a lot of code and it is a significant decrease in filesize.
glimmer-application-pipeline also uses rollup underneath and importing 3rd party modules is very effective
@MartinMalinda - Tree shaking as a whole does not work well. It can't tree shake lodash-es for many reasons. Here's an extremely simple example of tree-shaking failing.
This problem is not specific to rollup - it's that tree-shaking is difficult. Rich harris was working on a a different method to determine whether code causes side-effects, but the last commit of that branch was in january so I assume that work was deemed not time-effective.
It could be responsibility of each addon how to handle tree shaking - whether to tree shake 3rd party lib code, whether to tree shake ember modules that being exported.
If there 100 helpers the addon is exporting, it is quite straightforward to check which are used and which not in the parent app. They are generally pure functions without side effects.
I agree that having one global switch for tree shaking is probably not a good idea.
I see - I confused your mentioning of "tree shaking" to mean one provided by a bundler. Removing code using heuristics specific to ember is very reasonable.
I've found that in many of my projects that I use
ember-lodash
, I end up writing Ember helpers that mostly just call a Lodash function and pass along arguments. For example:This allows me to take advantage of Lodash transformations in my template (without having to make a CP):
Would there be interest in a PR that adds some of these helpers to the addon?