Use of send.bind(send, 'METHOD') prevents tree shaking with Rollup
See original GitHub issueI’m working with the next
v2 branch! This is so minor because it’s like… four lines. 😅
I’m working on a library that bundles in httpie
instead of importing it (because it’s so small, so why not? 🙌 ) and I noticed that even though I was only importing post
the other four helpers were also there. I guess Rollup is being extra careful with bind
and includes them in case of any side effects?
When I converted it to something like this (not necessarily recommending it):
export const get = (...args) => send('GET', ...args);
export const post = (...args) => send('POST', ...args);
export const patch = (...args) => send('PATCH', ...args);
export const del = (...args) => send('DELETE', ...args);
export const put = (...args) => send('PUT', ...args);
Then it’d tree shake just fine.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Not tree-shaking `.bind()` constants · Issue #2566 · rollup ... - GitHub
I've test both with & without treeshake.pureExternalModules and the results are the same. Expected Behavior. When importing send alone, none of the helper ......
Read more >Tree-Shaking in JavaScript with Rollup - CodinGame
Tree -shaking is the process of analyzing the code files that are required to run your application and then including only code that...
Read more >How To Make Tree Shakeable Libraries - Theodo blog
Tree shaking is a way to achieve dead code elimination by detecting which exports are unused in our application.
Read more >Reduce JavaScript payloads with tree shaking - web.dev
A diagram illustrating the process of downloading, decompressing, parsing, compiling, and executing The process of downloading and running JavaScript. Note that ...
Read more >Tree-shaking with rollup - Stack Overflow
Webpack can not treeshake a bundled file FYI. On the side of the project that using it, you have to specify sideEffects in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Whichever you prefer/are using. I’ll comb thru Monday to fill in anything missing and publish a patch
I think I’m going to leave
1.x
branch alone. I should get my act together and promotehttpie@next
to stable before year end. If you think it’s necessary before I get to that, please leave a shout 😃Closed by your #35 & released in
v2.0.0-next.12
– thanks!