Skip to content
Every tutorial here is 100% free — and always will be
LSLovableStudent

How do I remove unused code?

Last checked 31 Aug 2026

Short answer

Ask Lovable to search for unused components, imports and dependencies, or run a tool like ts-prune/depcheck via the terminal, then remove what's confirmed unused and re-test.

Why it matters

Unused code adds to bundle size (slower initial load), clutters the codebase for future edits, and makes it harder for Lovable's AI to reason about your app when you ask for changes.

Ways to find it

  • Ask Lovable directly:

Scan the project for components, functions and imports that are defined but never used, and list them without deleting anything yet.

  • Dependency check. Unused npm packages still get bundled or at least slow installs. If you have terminal/Dev Mode access, npx depcheck lists dependencies that nothing imports.
  • Dead export check. npx ts-prune (for TypeScript projects) lists exported symbols nothing else imports.
  • Route/page audit. Pages built during earlier iterations but no longer linked from navigation are easy to miss — check your router configuration for orphaned routes.

Process

  1. Generate the list of candidates (above) rather than deleting on sight.
  2. Confirm each one really is unused — search-based tools sometimes miss dynamic imports.
  3. Remove in small batches and re-test the app (or ask Lovable to do it) after each batch.
  4. Commit via Git sync before a big cleanup so you can revert if something breaks.

What usually goes wrong

Deleting a component that's still referenced by a dynamic import or a string-based route breaks the build in a way that's hard to trace. Use Version history to roll back a bad cleanup, and prefer small, verifiable batches over one large deletion pass. This pairs well with /questions/how-do-i-audit-a-lovable-project-s-performance as part of a general clean-up before launch.

Was this answer helpful?

Related questions

Website made, maintained and hosted by PromptSites.com

PromptSites logo