Skip to content

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

Closed
@olov

Description

@olov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions