Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Improve threeshaking with webpack #1377

Open
1 of 2 tasks
chuckmah opened this issue Oct 16, 2024 · 1 comment
Open
1 of 2 tasks

[Feature]: Improve threeshaking with webpack #1377

chuckmah opened this issue Oct 16, 2024 · 1 comment

Comments

@chuckmah
Copy link

Describe the feature

Currently , the bundling of the lib make it impossible for webpack to properly treeshake. When importing a single primitive the resulting webpack bundle contain all the code from all components and deps of the lib which is like 75kb minified. I guess this is related to an other feature request (#808)

From my investigation this is probably due to vitejs/vite#5174. I patched a radix-vue version using the solution proposed in vitejs/vite#5174 (comment) and I had proper treeshaking from webpack 5

Here's a snippet of my final patched vite.config.ts file

[... rest of the file]
    rollupOptions: {
      // make sure to externalize deps that shouldn't be bundled
      // into your library (Vue)
      external: ['vue', '@floating-ui/vue', '@internationalized/date', '@internationalized/number'],
      output: {
        preserveModules: true,

        // Provide global variables to use in the UMD build
        // for externalized deps
        globals: {
          'vue': 'Vue',
          '@floating-ui/vue': '@floating-ui/vue',
          '@internationalized/date': '@internationalized/date',
          '@internationalized/number': '@internationalized/number',
        },
        assetFileNames: (chunkInfo) => {
          if (chunkInfo.name === 'style.css')
            return 'index.css'
          return chunkInfo.name as string
        },
      },
    },


i'm not proposing this a proper PR because it probably break other bundler just posting for reference.

Thanks for this great lib

Additional information

  • I intend to submit a PR for this feature.
  • I have already implemented and/or tested this feature.
@zernonia
Copy link
Member

Thanks for the ticket and provided solution! Feel free to create a PR for this 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants