How do you stop a bundler from pulling in Node polyfills for one import?

Hey folks, I’m wiring up a small web app and I’m trying to keep the bundle lean, but one dependency keeps dragging in Node-ish polyfills and my chunk size jumps hard. The failure mode is it “works” in dev, then prod gets bloated and tree-shaking feels like it gives up.

// vite/rollup-ish setup
export default {
  optimizeDeps: {
    exclude: ["some-lib"],
  },
  resolve: {
    alias: {
      // I only need a tiny helper, but it seems to pull in the whole package
      "some-lib": "some-lib/dist/index.js",
    },
  },
};

What’s the cleanest way to force the browser-safe entry (or a subpath) so the bundler doesn’t inject Node polyfills, without forking the dependency or breaking future updates?

1 Like