question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use of send.bind(send, 'METHOD') prevents tree shaking with Rollup

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Nov 28, 2020

Whichever you prefer/are using. I’ll comb thru Monday to fill in anything missing and publish a patch

0reactions
lukeedcommented, Nov 30, 2020

I think I’m going to leave 1.x branch alone. I should get my act together and promote httpie@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found