Wydajność

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.

umiarkowanastatycznefe-perf-delivery

Dlaczego

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.

Poprawka

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.

Przykłady

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

Źródła

Fakty

Identyfikator
perf/no-whole-library-import
Waga
umiarkowana
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
jsx vue svelte astro
Uczy jej skill
fe-perf-delivery JavaScript, CSS and asset delivery
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

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