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

Reduce build size by swapping out lodash.assign for a minimal Object.assign #332

Closed
olov opened this issue Feb 23, 2017 · 1 comment · Fixed by #347
Closed

Reduce build size by swapping out lodash.assign for a minimal Object.assign #332

olov opened this issue Feb 23, 2017 · 1 comment · Fixed by #347
Milestone

Comments

@olov
Copy link

olov commented Feb 23, 2017

I did a clone of the repo followed by NODE_ENV=production scripts/build, which produced a 16826 bytes react-modal.min.js (5358 bytes gzipped).

Replacing the lodash assign import in ModalPortal.js with a minimal Object.assign polyfill (I took the TS one just for example):

function assign(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
}

...produced a 14516 bytes react-modal.min.js (4418 bytes gzipped).

That's an 18% (gzipped size) reduction, which adds up on slow networks and devices.

@jdalton
Copy link

jdalton commented Feb 23, 2017

In this case since only lodash.assign is being used you should totally replace it with babel-plugin-transform-object-assign. In other cases, when using Lodash and size is a concern, you should check out lodash-webpack-plugin. It disables features sets and edge cases by default to reduce bundle sizes.

@diasbruno diasbruno added this to the 1.7 milestone Mar 2, 2017
@claydiffrient claydiffrient modified the milestones: 2.0.0, 1.7 Mar 5, 2017
claydiffrient added a commit that referenced this issue Mar 5, 2017
This commit sets things up to work properly when
publishing to npm.  Prior to publishing the package
items from the src/ folder will be processed with Babel
and stored in the lib/ folder. The lib/ folder will
not be present in the repository.  The src/ folder similarly
will not be available when looking at the installed package.

In addition this commit also fixes #332 by adding the
`babel-plugin-transform-object-assign` plugin and removing
`lodash.assign`
claydiffrient added a commit that referenced this issue Mar 5, 2017
This commit sets things up to work properly when
publishing to npm.  Prior to publishing the package
items from the src/ folder will be processed with Babel
and stored in the lib/ folder. The lib/ folder will
not be present in the repository.  The src/ folder similarly
will not be available when looking at the installed package.

In addition this commit also fixes #332 by adding the
`babel-plugin-transform-object-assign` plugin and removing
`lodash.assign`
claydiffrient added a commit that referenced this issue Mar 24, 2017
* Update bundling scheme

This commit sets things up to work properly when
publishing to npm.  Prior to publishing the package
items from the src/ folder will be processed with Babel
and stored in the lib/ folder. The lib/ folder will
not be present in the repository.  The src/ folder similarly
will not be available when looking at the installed package.

In addition this commit also fixes #332 by adding the
`babel-plugin-transform-object-assign` plugin and removing
`lodash.assign`

* Update linting dependencies

This temporarily disables react/require-default-props
until it can be addressed in a separate commit.

* Make sure tests run using the proper source
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

Successfully merging a pull request may close this issue.

4 participants