nextjs-tree-shaking

Convert default exports to named exports and refactor barrel files for Next.js 15 tree-shaking.

1|Updated Jan 31, 2026
One-click install
npx skills add https://github.com/SilverAssist/performance-toolkit --skill nextjs-tree-shaking
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nextjs-tree-shaking
Source: https://github.com/SilverAssist/performance-toolkit/tree/main/src/templates/skills/nextjs-tree-shaking
Command: npx skills add https://github.com/SilverAssist/performance-toolkit --skill nextjs-tree-shaking

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps teams optimize Next.js 15 bundle size by converting default exports to named exports and refactoring barrel files to improve tree-shaking and load performance.

Core Features & Use Cases

  • Convert default exports to named exports to enhance tree-shaking and reduce bundle size.
  • Refactor barrel files (index.ts) to use explicit named re-exports for better static analysis.
  • Configure Next.js optimizePackageImports in next.config.mjs for granular bundling optimization.
  • Use the 'use cache' directive for function-level caching in Next.js 15 (experimental) to improve caching and HMR performance.
  • Applicable to Next.js 15 apps using App Router, server components, and complex component libraries.

Quick Start

Use the Next.js tree-shaking skill to audit your project and begin the migration:

  • Run: npx @silverassist/performance-toolkit --audit-exports to identify default export hotspots.
  • Convert identified default exports to named exports in key components and update barrel files.
  • Update next.config.mjs to enable optimizePackageImports and incorporate Next.js 15 caching directives.

Frequently Asked Questions about nextjs-tree-shaking

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize Next.js 15 bundle size by converting default exports to named exports?

To optimize Next.js 15 bundle size, you convert default exports to named exports and refactor barrel files to use explicit named re-exports, which enhances static analysis and tree-shaking. This reduces the amount of unused code shipped to the client.

How do I configure optimizePackageImports in next.config.mjs for App Router server components?

Configuring optimizePackageImports in next.config.mjs enables granular bundling optimization for App Router server components. By updating this configuration, you allow the Next.js compiler to perform more efficient tree-shaking on complex component libraries.

Why does refactoring barrel files improve tree-shaking in Next.js applications?

Refactoring barrel files improves tree-shaking because explicit named re-exports provide better static analysis targets. When index.ts files avoid default re-exports, bundlers can accurately identify and eliminate unused module exports from the final bundle.

Can I use the 'use cache' directive for function-level caching in Next.js 15?

Yes, you can use the experimental 'use cache' directive in Next.js 15 for function-level caching. This approach improves caching and Hot Module Replacement (HMR) performance within your App Router components and complex libraries.

What is the best way to audit a Next.js project for tree-shaking issues and default export hotspots?

The best way to audit tree-shaking issues is to run a static analysis tool like @silverassist/performance-toolkit with the --audit-exports flag. This identifies default export hotspots in your component libraries, guiding your named export migration.

Does this tree-shaking migration approach work for large component libraries using App Router?

Yes, this migration approach specifically targets Next.js 15 apps using App Router, server components, and complex component libraries. Converting default exports to named exports and updating barrel files ensures large libraries are bundled efficiently.