Externalize ReactTransitionGroup (fixes big file size)#474
Externalize ReactTransitionGroup (fixes big file size)#474eddywashere merged 4 commits intoreactstrap:masterfrom
Conversation
|
👍 |
|
We should also add bundle size as a step in the build process, like this: https://github.com/developit/vhtml/blob/master/package.json#L13 |
|
@balloob If the references to e.g. Change: If so, I'd argue that's the more normalized solution (Updating the few locations that use the package) and then just leaving one single top level package global/exclude. The older documentation referenced cherry picking but was recently updated to use proper ES imports: |
e06f2ce to
b64cb82
Compare
|
@virgofx good point. I have addressed your comments 👍 |
|
@nathancahill I will leave that up to a future PR. Opened issue #475 to discuss it. |
|
@TheSharpieOne You've commented variations of your comment at three different spots. I will respond to all of them here. You state that every lib ever is pointing at unbundled files. However, React will ship bundled by Rollup as a single build for both development and production starting React 16: https://unpkg.com/[email protected]/index.js See this talk by one of the Facebook React maintainers at ReactEurope about how the size and load times both went down with 10%: https://youtu.be/djOc1EK07Tk?t=300 Since The warning was because the 4.6 bundle was broken and actually included the whole of React in the compiled bundle! #433 didn't fix it, it just hid the problem for npm users while still having a broken build for UMD users. This PR will fix the build again and no warning will be issued. |
|
When with react 16, they generate cjs and umd, right now and with your changes there is only umd with reactstrap. React 16 doesn't reference the umd output in their package.json. |
|
That can be tweaked by marking lodash.omit and lodash.tonumber as external for a CJS build. Would save us 10kB. Feel free to submit that as a followup PR once this one has been merged. This PR saves 240kB for UMD bundles and 29-39kB* for CommonJS bundles. On top of that the loading time will be faster due to the flat bundle that Rollup creates. *: 39kB for only including the Babel helpers once. Up to 10kB of waste if consumer also depends on lodash.omit. |
|
@TheSharpieOne I have reverted the change to main. No reason to delay fixing the ES/UMD bundles over a discussion about the CJS entrypoint. |
|
#477 includes this PR and creates a CommonJS build without any dependency included. |
Reactstrap bundle size jumped from 95kB to 335kB with the release of v4.6.0 (#472).
After observing the bundled output using
source-map-explorerI noticed that React, ReactDOM and React Transition Group all three were part of the bundle! Visualized bundle.This was introduced when upgrading the React Transition Group package in #399. The imports were updated to point at modules that live under the
react-transition-grouppackage. For example:By importing a module under the package, Rollup no longer found a matching entry in the list of imports that should be treated as external. This resulted in Rollup including it in the bundle.
This PR fixes it by setting up the correct external entries for the React Transition Group package and the imports that we use. I have also added back the entries to the global list for React Transition Group that were removed in #399 so that UMD builds will work correctly when used together with the UMD builds of React Transition Group. Visualized bundle after the fix.
Fixes #472.
This PR also reverts #433. #433 worked around the wrong bundling by pointing at the
libfolder. This is wrong because the lib folder contains individually transpiled files. By being individually transpiled, each file will contain a copy of the babel helpers that are used, resulting in each component being bigger than it should be.