prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
154 stars 40 forks source link

Including polyfills increases bundle size #27

Closed kaYcee closed 4 years ago

kaYcee commented 4 years ago

Not an issue but a suggestion for improvement:

Based on bundlephobia.com, bundle size has recently increased from 71KB minified (1.0.0) to 217KB minified (1.0.1), which is a twofold increase. I guess it has mainly to do with the now bundled polyfills.

It seems to be best practice now to indicate in the README when polyfills are required but let the user decide how to implement them (if at all) - rather then bundling them directly. Otherwise the client bundle gets bloated by various polyfills.

StarpTech commented 4 years ago

I just wanted to open the same issue. We see the same increase of more than ~200kB (45kB gzipped) for our product page. We only use:

import { RichText } from 'prismic-reactjs';

This is not acceptable in our case, therefore we can't use this library.

StarpTech commented 4 years ago

The common way to include polyfills is at project root. For example in angular (polyfill.ts), next.js (webpack config), gatsby (polyfill automatically even node_modules) etc.. Imagine every library would ship it's own es6 polyfills that would :octopus: :bomb: really fast.

hypervillain commented 4 years ago

Hey guys, I'm sorry you're experiencing such a huge issue and I'm totally responsible for this. I went a bit fast on solving the prismic-richtext related issue and did not think through bundle size at all.

I'll take some time tomorrow to make a PR on this subject

IikkaWinter commented 4 years ago

We are only using RichText component from the lib and the size is still 77.1KB easily being the largest piece of 3rd party code in our app so there is a lot of optimisation to be done. This is why we are also considering dropping it completely.

hypervillain commented 4 years ago

Hey guys,

I did a PR that you can preview here: https://github.com/prismicio/prismic-reactjs/pull/28 It significantly reduces the size of the bundle (around 22k).

If you find other optimisations, I would love to have your feedback. In the meantime I'll find a reviewer and will probably deploy 1.1.0 later today

hypervillain commented 4 years ago

Deployed to 1.1.0, can you guys give it a try? I'll close in the meantime, feel free to reopen!

IikkaWinter commented 4 years ago

@hypervillain were you supposed to release the changes? The latest is still 1.0.1.