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.

Builds using esModules/Support Tree Shaking

See original GitHub issue

(This issue tracker is only for bug reports or feature requests, if this is neither, please choose appropriate channel from http://bluebirdjs.com/docs/support.html)

Please answer the questions the best you can:

1) What version of bluebird is the issue happening on? All of them.

2) What platform and version? (For example Node.js 0.12 or Google Chrome 32) Every Platform/Every Version

3) Did this issue happen with earlier version of bluebird? Yes

(Write description of your issue here, stack traces from errors and code that reproduces the issue are helpful)

I’m not sure if this is already represented in the Bluebird pipeline, or I’ve missed another issue that captures this (I just searched for “tree-shaking”, entirely possible). If so, this can be closed.

It would be nice if Bluebird were bundled using a well-known module bundler, or could in some way capitalize on the tree-shaking functionality that many well-known module bundlers provide.

I am requiring Bluebird into a project of mine. It is quite large, but I am willing to include it because of the considerable speed advantages I get out of using it (seriously, awesome work). I am then using Webpack 2 (webpack@2.1.0-beta26) to bundle my project.

This project does not use any of the ancillary methods bluebird provides (map, filter, each, etc), but because the module is pre-bundled (using “fs”), I cannot shake any of the modules that are in the bluebird.js main.

In addition, I have tried explicitly including Bluebird in my build and referencing bluebird only from ‘bluebird/js/release/bluebird’:

loaders: [
    {
         test: /\.js$/,
         loader: 'babel-loader',
         exclude: /node_modules\/(?!bluebird)/
    }
]
import bluebird from 'bluebird/js/release/bluebird';

but this results in a build of exactly the same size. It appears as though a bluebird.core.js module is distributed as well, which is slightly smaller, but it also appears to not be as performant as the main module.

In addition, if there are any workarounds, I would love to try them out.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:10
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
benderTheCrimecommented, Nov 18, 2016

Also, as the node-bluebird steps to create a custom build suggest, this has to be done from a cloned instance of bluebird. There is no gruntfile associated with Bluebird, so actually adding this to my build pipeline does not work.

4reactions
benderTheCrimecommented, Nov 17, 2016

@spion I didn’t know that was a possibility, thank you for passing along these links.

Nevertheless, I would classify this under the “workarounds” I mentioned in my issue. It is nice to be able to conditionalize the optional modules based on a build, but it seems like a lot of work for a dependency within any project’s build lifecycle.

If I was to do this, I would have to explicitly add a statement to my build scripts that built bluebird without those modules every time my packages were resolved, and rebuild if my project starts to use one of the optional methods is called within my project (imposing some small amount of overhead).

Therefore, I think this is still a relevant issue to track. It’s unrealistic to expect users to create implementation-specific builds when there is a perfectly good vehicle to prevent them from having to do so.

Perhaps https://github.com/rollup/rollup/wiki/jsnext:main?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reduce JavaScript payloads with tree shaking - web.dev
In production builds, webpack can be configured to "shake" off exports from ES6 modules that weren't explicitly imported, making those production builds smaller ......
Read more >
Tree Shaking - webpack
Tree shaking is a term commonly used in the JavaScript context for dead-code ... The webpack 2 release came with built-in support for...
Read more >
Tree-Shaking: A Reference Guide - Smashing Magazine
Tree -shaking” is a must-have performance optimization when bundling JavaScript. In this article, we dive deeper on how exactly it works and ...
Read more >
Dynamically Import ESModules and Tree Shake them too!
In Webpack, tree shaking works only when you build for production. Read more about Tree Shaking in this book and in the documentation....
Read more >
Building a Tree Shaking Friendly JavaScript Package
tree -shaking-react. June 20, 2021 - Amr Salama. At bene : studio we love knowledge sharing to help the community of professionals. With...
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