opentok-react icon indicating copy to clipboard operation
opentok-react copied to clipboard

Optimise lodash imports for smaller webpack bundles

Open gilmoreorless opened this issue 6 years ago • 1 comments

Importing multiple modules from lodash/fp results in neat code, but it has an unfortunate side effect in webpack and browserify builds. Importing from the top-level package brings in the entire lodash library, instead of just the two methods used.

This PR splits the import into 2 separate imports, in the same way as the lodash/once import above them.

To test the result, I created a super-simple webpack project, where the only code is this:

import { OTPublisher } from 'opentok-react';

Running webpack on this file in production mode, with opentok-react version 0.9.0, results in the following file sizes:

File Size
index.js 113K
index.js.gz 36K

Running the same build using this PR:

File Size
index.js 88K
index.js.gz 26K

gilmoreorless avatar Feb 25 '20 23:02 gilmoreorless

Came across this issue when analysing my build bundle. Would be great to trim this additional import out!

taijuten avatar Sep 03 '20 09:09 taijuten