Skip to main content
These rules help you minimize your JavaScript bundle size by catching import patterns that bloat your bundle.

Rules

Severity: warn
Rule ID: react-doctor/no-barrel-import
Detects imports from barrel/index files. Barrel files can prevent tree-shaking and include unnecessary code in your bundle.Why it’s bad:
  • Bundlers may include entire barrel file
  • Tree-shaking often fails with barrel exports
  • Slower build times
Bad:
Good:
Detected patterns: /index, /index.js, /index.ts, /index.tsx, /index.mjs
Severity: warn
Rule ID: react-doctor/no-full-lodash-import
Prevents importing the entire lodash library. The full lodash library is ~70kb minified, but you typically only need a few functions.Bad:
Good:
With proper tree-shaking configuration, lodash-es can be imported directly. But lodash (CommonJS) always requires per-function imports.
Severity: warn
Rule ID: react-doctor/no-moment
Suggests using date-fns or dayjs instead of moment.js. Moment.js is 300kb+ minified and no longer maintained.Bad:
Good:
Bundle sizes:
  • moment.js: ~300kb
  • date-fns: ~13kb (with tree-shaking)
  • dayjs: ~2kb
Severity: warn
Rule ID: react-doctor/prefer-dynamic-import
Recommends code splitting for heavy libraries using React.lazy() or next/dynamic.Heavy libraries detected:
  • @monaco-editor/react
  • recharts
  • @react-pdf/renderer
  • react-quill
  • @codemirror/view
  • chart.js
  • draft-js
Bad:
Good:
Severity: warn
Rule ID: react-doctor/use-lazy-motion
Enforces using LazyMotion with the m export instead of the full motion export from framer-motion. This saves ~30kb in bundle size.Bad:
Good:
Bundle savings:
  • Full motion: ~60kb
  • LazyMotion + domAnimation: ~30kb
  • Savings: ~30kb (50%)
Severity: warn
Rule ID: react-doctor/no-undeferred-third-party
Requires defer or async attributes on third-party <script> tags. Synchronous scripts block the browser’s first paint.Bad:
Good:
defer vs async:
  • defer: Script executes after HTML parsing, in order
  • async: Script executes as soon as downloaded, out of order
  • Use defer for scripts that depend on DOM or other scripts
  • Use async for independent scripts like analytics

Bundle Analysis Tools

Use these tools to analyze your bundle:

Best Practices

Import Strategy

  1. Direct imports for tree-shakeable libraries
  2. Dynamic imports for heavy components
  3. Avoid barrel files in your own code
  4. Per-function imports for lodash and similar utilities

Code Splitting

  • Split routes/pages by default
  • Lazy load heavy components (editors, charts, maps)
  • Lazy load rarely-used features
  • Use Suspense boundaries strategically