Optimize Build Instant
A command template for performance workflows. Streamlines development with pre-configured patterns and best practices.
Optimize Build Instant
Instantly analyze and optimize your build system configuration for faster compilation, smaller output, and more efficient caching across Webpack, Vite, Rollup, Gradle, and other build tools.
When to Use This Command
Run this command when...
- Build times have grown unacceptably long and you need immediate improvements to the build pipeline
- You want to optimize build configuration without deep expertise in your specific build tool
- A clean build takes more than a few minutes and you suspect misconfiguration or missing optimizations
- You need to compare clean build, incremental build, and development server startup performance
- You are migrating build tools and want to ensure optimal configuration for the new system
Quick Start
# .claude/commands/optimize-build-instant.md --- name: Optimize Build Instant description: Analyze and optimize build system for speed and output size command: true --- Optimize build: $ARGUMENTS 1. Identify build system and analyze configuration 2. Measure baseline build performance 3. Apply optimizations for speed, caching, and output 4. Verify improvements with comparative measurements
# Invoke the command claude "/optimize-build-instant webpack production build" # Expected output # > Detected: Webpack 5 with babel-loader, ts-loader, css-loader # > Baseline measurements: # > Clean build: 47s | Incremental: 12s | Output: 4.2MB # > Applying optimizations: # > 1. Enable persistent caching (filesystem cache) # > 2. Configure parallel thread-loader for ts-loader # > 3. Switch to esbuild-loader for transpilation # > 4. Add module concatenation and tree shaking # > 5. Configure split chunks for vendor separation # > After optimization: # > Clean build: 18s | Incremental: 3s | Output: 2.8MB # > Improvement: 62% faster clean build, 75% faster incremental
Core Concepts
| Concept | Description |
|---|---|
| Build System Detection | Identifies the build tool, version, plugins, and loader chain automatically |
| Performance Baseline | Measures clean build, incremental build, and dev server times before changes |
| Cache Optimization | Configures filesystem, memory, and module caches for maximum reuse |
| Parallelization | Enables multi-threaded compilation where supported by the build tool |
| Output Optimization | Reduces bundle size through tree shaking, code splitting, and minification tuning |
Build Optimization Pipeline
=============================
Detect Build System
|
+------+------+------+------+
| | | | |
Webpack Vite Rollup Gradle Other
|
[Measure Baseline]
Clean | Incremental | Dev Server
|
[Apply Optimizations]
Cache | Parallel | Loaders | Splitting
|
[Measure After]
Clean | Incremental | Dev Server
|
[Report Delta]
47s->18s (62% faster)
Configuration
| Parameter | Description | Default | Example | Required |
|---|---|---|---|---|
$ARGUMENTS | Build system or specific build target to optimize | auto-detect | "webpack production" | No |
build_tool | Specific build tool if auto-detection fails | auto-detect | "vite", "rollup" | No |
target_metric | Primary metric to optimize for | build_time | "output_size", "dev_startup" | No |
aggressive | Apply more aggressive optimizations that may affect debugging | false | true | No |
measure_iterations | Number of build runs for baseline measurement | 2 | 5 | No |
Best Practices
-
Measure before optimizing -- Always capture baseline numbers so you can quantify improvements. Build time varies between runs, so use multiple iterations for reliable baselines.
-
Optimize incrementally -- Apply one category of optimization at a time (caching, then parallelization, then loaders) to isolate which changes have the most impact.
-
Keep development and production configs separate -- Dev builds should prioritize speed and source maps over output size. Production builds should prioritize output size and minification.
-
Verify output correctness after optimization -- Run your full test suite and manually check the built application after each optimization to ensure no functionality was broken.
-
Document build configuration changes -- Build configs are notoriously hard to debug. Add comments explaining why each optimization is configured the way it is.
Common Issues
Cache invalidation causes stale builds: Filesystem caching can serve outdated modules after dependency updates. Clear the cache directory after major dependency changes or add cache-busting configuration.
Thread-loader breaks certain plugins: Not all loaders and plugins are thread-safe. If parallel compilation causes cryptic errors, identify the incompatible loader and exclude it from threading.
Tree shaking removes needed code: Side-effect-free module annotations may incorrectly mark modules as shakeable. Add affected modules to the sideEffects list in package.json to prevent removal.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Git Commit Message Generator
Generates well-structured conventional commit messages by analyzing staged changes. Follows Conventional Commits spec with scope detection.
React Component Scaffolder
Scaffolds a complete React component with TypeScript types, Tailwind styles, Storybook stories, and unit tests. Follows project conventions automatically.
CI/CD Pipeline Generator
Generates GitHub Actions workflows for CI/CD including linting, testing, building, and deploying. Detects project stack automatically.