Skip to content
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

🙋 Document how to remove unused JavaScript code from the bundle #475

Open
dolebas opened this issue Apr 25, 2018 · 2 comments
Open

🙋 Document how to remove unused JavaScript code from the bundle #475

dolebas opened this issue Apr 25, 2018 · 2 comments

Comments

@dolebas
Copy link

dolebas commented Apr 25, 2018

🙋 feature request

Expected Behavior

When a library is required but parts of it are not used, I should be able to figure out how to remove the unused code from the bundle.

Current Behavior

If a library is added with var abc = require('library'), unused JavaScript is not removed from the bundle by default.

Code Sample

npx create-choo-app and add web3 = require('web3') to index.js

Your Environment

Software Version(s)
Package bankai@9.11.1
Runtime node@v8.11.1
Package Manager npm@5.8.0
Operating System macOS@10.13.4
@goto-bus-stop
Copy link
Member

I don't know if we can safely do this because some modules rely on side effects. eg:

require('babel-polyfill')
new WeakSet()

here babel-polyfill does not appear to be "used", but in old browsers the WeakSet global variable would not be available without that require call.

@dolebas
Copy link
Author

dolebas commented Apr 25, 2018

The solution in my case was to follow your good advice and find a different library with a better separation of concerns.

Requiring the specific export 'ethers/providers' perfectly removed unused/not required code in the 'ethers' library from the bundle.

Maybe docs could require the wording "not required" instead of "unused" where it makes sense? =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants