tremor icon indicating copy to clipboard operation
tremor copied to clipboard

Reduction in Bundle Size/ Tree shaking problem?

Open deevo-sage opened this issue 1 year ago • 10 comments

What problem does this feature solve?

image image

The bundle size increases drastically when using tremor. but if I importing directly from the Dist folder, if you see the '/real-user-report' path

image

just importing from the dist path reduced the bundle size by 200 kb and I'm just using Card on that page

for the '/performance' path, I'm using a lot more components and the bundle size was 430KB and again just shifting to dist import for all the charts and elements the bundle size reduced around 200KB

What does the proposed API look like?

I Assume there is some issue with Tree Shaking.

deevo-sage avatar Aug 04 '23 08:08 deevo-sage

#493 #489

severinlandolt avatar Aug 05 '23 00:08 severinlandolt

I tried a few things using Vite.

  1. Vite as per tutorial vite1-result

  2. Vite + deep imports vite2-result

  3. Vite + '"sideEffects": false' added '"sideEffects": false' to './node_modules/@tremor/react/package.json' Please note that I haven't verified the functionality. vite3-result

The Code is here

Many libraries have a sideEffect field, but tremor does not. Wouldn't this be a solution?

motinados avatar Aug 11 '23 01:08 motinados

yes indeed, that's most likely the solution. Thanks for trying that out! Feel free to open a PR and add the toggle to the package.json if you like :)

mitrotasios avatar Aug 11 '23 21:08 mitrotasios

I also tried a few things with Nextjs.

  • Nextjs13 next1-result

  • Nextjs13 + deep imports next2-result

  • Nextjs13 + sideEffects: false
    next3-result

Just the sideEffects field is not enough for Nextjs.

motinados avatar Aug 12 '23 21:08 motinados

Thank you!

mitrotasios avatar Aug 16 '23 16:08 mitrotasios

I am curious. Are changes to the tremor source code feasible and planned, such that the bundle size with normal imports can be as small as it is with deep import currently?

Thank you very much for providing us with a great dashboarding solution Tremor has become.

DostalJ avatar Aug 16 '23 18:08 DostalJ

This code works for my nextjs app. Can someone please try it? Note that next@canary is required.

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
    experimental: {
        optimizePackageImports: [
          "@tremor/react"
        ]
    }
}
module.exports = nextConfig

package.json

"next": "^13.4.20-canary.12"

motinados avatar Sep 02 '23 21:09 motinados

Results of optimizedPackegeImports on my app with the latest "next": "^13.4.20-canary.12" Thanks for help!

Before: Screenshot 2023-09-11 at 15 29 13

After: Screenshot 2023-09-11 at 15 29 19

DostalJ avatar Sep 11 '23 13:09 DostalJ

@DostalJ In my case the optimizePackageImports doesnt make a big impact because I am only using the charts from tremor, the rest of the components are from headlessui and shadcn. In your case I suppose you just import the tremor button for example in one page, and in that cases is where the impact is much bigger.

angelhodar avatar Oct 11 '23 13:10 angelhodar

Looks like Next.js is optimizing @tremor/react by default: https://nextjs.org/docs/app/api-reference/next-config-js/optimizePackageImports

paullaros avatar Jan 24 '24 20:01 paullaros