Dodi’s scrap bin: a real toolkit package, four files. Pick what app.js uses, how it imports (named, kit.name, kit[key], require) and sideEffects; a model of…
Utility libraries (lodash, date-fns, icons) hold hundreds of functions when you use three. A bundler only dares to drop what it can prove is unused and does nothing when loaded: static imports, fixed names, and an honest sideEffects. That is the difference between a 12 KB and a 240 KB bundle.
A bundler drops what it can prove is unused and has no effect
lodash is written as CommonJS: the bundler takes it whole, like require() here. Use lodash-es with named imports (import { debounce } from "lodash-es"), or one file per function (lodash/debounce)."sideEffects": false, then CSS or a polyfill is gone from the bundle A file imported for its effect (import "./style.css", a polyfill) is dropped too. List them: "sideEffects": ["*.css", "./src/polyfill.js"].vite dev the bundle does not shrink at all vite dev makes no bundle: the browser loads every file as an ES module, like the job board in the scene. Measure the real size with vite build.sideEffects, the IKON_BENGKEL = … line goes in although nobody uses ikonBan."sideEffects": false ikon.js leaves the bundle whole.sideEffects: false: the bundle breaks when it runs.import * as kit kit.rupiah by a fixed name: even a namespace is shaken.