#Lib mode bundle size is larger then default build, why?

1 messages · Page 1 of 1 (latest)

grim basin
#

I am trying to build a library and i am getting incorrect bundle size and i cannot seems to find material about this on the internet or chatgpt.

When i use default config

export default defineConfig({
  plugins: [react()],
});

I get small bundle size.
when i do

export default defineConfig({
  plugins: [react()],
  build: {
    reportCompressedSize: true,
    lib: {
      entry: resolve(__dirname, "src/lib.ts"),
      name: "lib",
      fileName: (format) => `lib.${format}.js`,
    },
  }
});

I am getting almost 5 times larger bundle size and i cannot find logical explanation in the docs?
Could someone enlighten me please why this happens ?

dawn blaze
#

try react({ jsxRuntime: 'classic', }), for react plugin

#

And regarding why I recommend you change the runtime

#

In library mode, all import.meta.env.* usage are statically replaced when building for production. However, process.env.* usage are not, so that consumers of your library can dynamically change it. If this is undesirable, you can use define: { 'process.env.NODE_ENV': '"production"' } for example to statically replace them.

#

In my case, I got "development" and "production" runtime code injected because of the process.env* twist for the lib mode

#

I hope that would help you to save some KBs

#

but define: { 'process.env.NODE_ENV': '"production"' } also works