lamina icon indicating copy to clipboard operation
lamina copied to clipboard

Tree shaking of debug code?

Open andrewthebold opened this issue 2 years ago • 3 comments

I noticed that the DebugLayerMaterial code adds ~50KB gzipped to my production js bundle even if I'm not using the debug layer. Looks like the main reason is because it's importing leva and its dependencies. I think this is something like an extra 2-3x the size of lamina's core code.

Tested with webpack and vite, but it's possible this is just my setup. I did a hacky fix with my bundler to alias leva to an empty exports file in production, but it would be nice to have the debug code automatically excluded if unused.

(Also, love the library!)

andrewthebold avatar Apr 30 '22 21:04 andrewthebold

Thanks!

I'm not too familiear with tree shaking but in the next release 1.2.0 the debugger will be broken off into lamina/debug. Correct me if i'm wrong but that should mean that as long as lamina/debug is not imported, Leva will not end up in the bundle.

You can follow the progress of 1.2.0 in #29 however beware, its an in-dev branch and quite a lot might be broken up till release

FarazzShaikh avatar May 01 '22 10:05 FarazzShaikh

Yeah sounds like that'll work. I was going to suggest an experience like react query's devtools, which conditionally imports the module depending on the NODE_ENV, but realize there's probably use cases to intentionally ship the lamina debugger.

andrewthebold avatar May 02 '22 10:05 andrewthebold

Lamina dependency on levas dependency on radix-ui is causing some conflicts. Would be great to have it conditionally!

emcfarlane avatar Dec 04 '22 02:12 emcfarlane