Why is one tiny import dragging a huge chunk into my bundle?

Yo folks, I’m in the middle of wiring up a Vite + React app and trying to keep the initial bundle slim, but one “harmless” helper import is suddenly pulling in a big dependency tree and wrecking first load.

// used in a couple components
import { format } from "date-fns";
import { enUS } from "date-fns/locale";

export function pretty(ts) {
  return format(new Date(ts), "PPpp", { locale: enUS });
}

What’s the practical way to confirm exactly why this import isn’t tree-shaking cleanly and fix it without playing whack-a-mole with manual aliases or swapping libraries?

1 Like