Performance

perf/no-whole-library-import

Client code does not import all of lodash or moment; use lodash-es, per-method imports, Intl or the platform.

moderatestaticfe-perf-delivery

Why

The lodash package is CommonJS, so bundlers cannot drop the functions you do not use: even import { debounce } from 'lodash' ships the whole library. Moment.js is in maintenance mode and brings its locale data. Both add tens of kilobytes that every visitor downloads and parses.

Fix

Import from lodash-es (tree-shakable) or a single-method path (lodash/debounce), or replace the call with the platform (structuredClone, Array.prototype.flat, Object.groupBy). Replace Moment with Intl.DateTimeFormat and Intl.RelativeTimeFormat, or a small modular date library.

Examples

// bad
import { debounce } from 'lodash'
import moment from 'moment'
// good
import { debounce } from 'lodash-es'
const fmt = new Intl.DateTimeFormat('en-GB', { dateStyle: 'long' })

Sources

Facts

Id
perf/no-whole-library-import
Severity
moderate
Check
static checked in the source by audit
Applies to
jsx vue svelte astro
Taught by the skill
fe-perf-delivery JavaScript, CSS and asset delivery
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain perf/no-whole-library-import