balena-io / balena-sdk

The SDK to make balena powered JavaScript applications.
https://www.balena.io/
Apache License 2.0
145 stars 46 forks source link

Reduce bundle size of our larger external dependencies #250

Open pimterry opened 7 years ago

pimterry commented 7 years ago

See https://github.com/resin-io/resin-sdk/pull/248#issuecomment-271399203 and https://github.com/resin-io/resin-sdk/pull/248#issuecomment-271401600.

This could potentially reduce the browser build size by quite a bit, depending on what we can drop. Could provide bring-your-own-bluebird and all-inclusive builds. Should be able to trim lodash usage down significantly if we depend on individual modules instead of the whole bundle

emirotin commented 7 years ago

Should be able to trim lodash usage down significantly if we depend on individual modules instead of the whole bundle.

Do we depend on the whole bundle? Can you trace which part specifically? Do you actually mean the package.json dependency or the full import somewhere? Because I've done my best to switch all the dependent modules to only import individual functions like require('lodash/assign') and it has reduced the bundle size in my experiments.

pimterry commented 7 years ago

You're right, it's not the whole bundle. We do only every import individual modules, it's just that there's so many of them that the size still adds up to quite a bit (130K/1.2M raw, 30K/500K minified). Might not be any easy wins in that case though.

emirotin commented 7 years ago

Yeah I've also replaced with natives (map/filter/forEach) where possible.

On Tue, Jan 10, 2017 at 6:19 PM, Tim Perry notifications@github.com wrote:

You're right, it's not the whole bundle. We do only every import individual modules, it's just that there's so many of them that the size still adds up to quite a bit (130K/1.2M raw, 30K/500K minified). Might not be any easy wins in that case though.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/resin-io/resin-sdk/issues/250#issuecomment-271602528, or mute the thread https://github.com/notifications/unsubscribe-auth/AAgGCGvpzYBdiZiCuWvX6mrAf_escnJNks5rQ6F8gaJpZM4LetzC .

-- Eugene Mirotin Senior Frontend Engineer site: Resin.io https://resin.io/, twitter: @resin_io https://twitter.com/resin_io

emirotin commented 7 years ago

Re documenting the exclusion of specific modules from the browser build the spec defines the way to do that in the package.json: https://github.com/defunctzombie/package-browser-field-spec#ignore-a-module

We should only check if Webpack understands this (as we want to use the SDK from the UI which uses Webpack, and just want this to be nicely compatible with Webpack).