New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tree-shaking not eliminating some dead code #2672
Comments
var union = unionBy(identity); could throw an error and will therefore retain it. Unfortunately due to the complexity involved I would not expect any improvements any time soon here. |
Ah I see, thanks a lot! I guess I'm still kinda puzzled because in the original module: // mapper.js
import * as _ from "lamb";
export const mapWithA = _.mapWith(_.getKey("a"));
I thought it might have been that Rollup finds import {mapWith, getKey} from "lamb";
export const mapWithA = mapWith(getKey("a")); but with same result, so I'm guessing Rollup is not aware of the fact that Also, if the reason to keep By the way I tried modifying |
This line of code is indirectly executed upon loading the module and must be retained due to its side effects: var union = unionBy(identity); Once package |
At least if package author will be definitely sure a package doesn't have side effects. I would refactor the lib to not rely on such "feature". |
The package author would be in a position to know what their code does to make that assessment. Refactoring is not always possible or practical. |
It will come at some point, time is the limiting factor |
@mindrones fwiw if https://github.com/mindrones/lambsplittest is patched to use deep imports it would achieve the same smaller output sought. This would be the net effect of the package diff --git a/src/mapWith.js b/src/mapWith.js
index 8dca92e..a537e5a 100644
--- a/src/mapWith.js
+++ b/src/mapWith.js
@@ -1,3 +1,3 @@
-import * as _ from "./lamb/src/index";
+import { default as mapWith } from "lamb/src/core/mapWith";
-export const mapWithA = _.mapWith(x => x.a);
+export const mapWithA = mapWith(x => x.a);
diff --git a/src/mapper.js b/src/mapper.js
index d5113b2..de817ab 100644
--- a/src/mapper.js
+++ b/src/mapper.js
@@ -1,3 +1,4 @@
-import {mapWith, getKey} from "./lamb/src/index";
+import { default as mapWith } from "lamb/src/core/mapWith";
+import { default as getKey } from "lamb/src/object/getKey";
export const mapWithA = mapWith(getKey("a"));
diff --git a/src/splitter.js b/src/splitter.js
index cd43a70..626fdf2 100644
--- a/src/splitter.js
+++ b/src/splitter.js
@@ -1,6 +1,7 @@
-import * as _ from "./lamb/src/index";
+import { default as generic } from "lamb/src/core/generic";
+import { default as partial } from "lamb/src/core/partial";
+import { default as __ } from "lamb/src/core/__";
-export const split = _.generic(String.prototype.split);
-
-export const splitBy = x => _.partial(split, [_.__, x]);
+export const split = generic(String.prototype.split);
+export const splitBy = x => partial(split, [__, x]);
export const splitByDot = splitBy(".");
|
I am still puzzled (sorry! :) in this build? Thanks! |
@kzc ah that is indeed a great solution, I'll use that while waiting for |
The difference is that in order to construct the var union = unionBy(identity);
export default union;
|
…r than as a peer dependency: Will have to keep an eye on the bundles size as for now rollup doesn't tree-shake code indirectly executed upon loading if it is assumed to have side effects. Later on using sideEffects: false in package.json will inform rollup that we are sure that loading modules won't cause sfx and will drop more code. See: rollup/rollup#2672
I think this can be close after #2844, thanks a lot for that! |
How Do We Reproduce?
git clone https://github.com/mindrones/lambsplittest
npm i
npm run build
Expected Behavior
Builds should contain only used functions.
Actual Behavior
Some of the builds contain apparenty unused functions.
For example I don't understand why I'm finding
var union = unionBy(identity);
inbuild/mapper.mjs
, asunion
is not referenced anywhere insrc/mapper.js
or in code used bymapWith
andgetKey
.build/mapper_manually_tree_shaked.mjs
is a working version of the same build but manually tree-shaked, removing the unused parts: here you can see what I removed.As you can see I also tried to build with the options
treeshake: {propertyReadSideEffects: false}
andtreeshake: {pureExternalModules: true}
, with no luck.The text was updated successfully, but these errors were encountered: