Successfully modernized the Catalyst React plugin to support both Vite and Webpack build tools with automatic detection and seamless integration.
- ✅ Created
BuildToolDetectorclass with intelligent detection logic - ✅ Supports detection via package.json dependencies
- ✅ Supports detection via configuration files (vite.config.js, webpack.config.js)
- ✅ Implements priority system (Vite > Webpack)
- ✅ Provides detailed build tool information
- ✅ Created
BaseBuildAdapterabstract class - ✅ Implemented
ViteAdapterwith full Vite support - ✅ Implemented
WebpackAdapterwrapping existing functionality - ✅ Maintains backward compatibility with existing projects
- ✅ Project validation (dependencies, files, React version)
- ✅ Production build with environment variables
- ✅ Development server with HMR
- ✅ Build output reporting with file sizes
- ✅ TypeScript support (.ts, .tsx files)
- ✅ Multiple entry point detection (main.tsx, index.tsx, etc.)
- ✅ Support for VITE_ prefix (Vite projects)
- ✅ Support for REACT_APP_ prefix (Webpack projects)
- ✅ Build tool-specific filtering
- ✅ .env file hierarchy support
- ✅ dotenv and dotenv-expand integration
- ✅ Vite-specific path handling
- ✅ Support for index.html at root (Vite) or public/ (Webpack)
- ✅ Multiple entry point names (main.tsx, index.tsx, etc.)
- ✅ Build output directory handling (dist for Vite, build for Webpack)
- ✅ Created
PluginErrorclass with categories - ✅ Formatted error messages with suggestions
- ✅ ANSI color formatting for different error types
- ✅ Enhanced logger with colored output
- ✅ Debug logging for build tool detection
- ✅ File size calculation for both build tools
- ✅ Gzipped size display
- ✅ Size threshold warnings
- ✅ Size difference tracking
- ✅ Formatted output matching Webpack style
- ✅ Updated main plugin entry point (lib/index.js)
- ✅ Automatic adapter selection based on detection
- ✅ Seamless validate/build/start operations
- ✅ Maintained existing API compatibility
- ✅ Added Vite as optional peer dependency
- ✅ Added @vitejs/plugin-react as optional peer dependency
- ✅ Updated TypeScript support (^3.2.1 || ^4 || ^5)
- ✅ Added required utility dependencies (filesize, gzip-size, etc.)
- ✅ Unit tests for BuildToolDetector
- ✅ Unit tests for environment variable handling
- ✅ Unit tests for PluginError class
- ✅ Jest configuration setup
- ✅ Updated README with Vite support information
- ✅ Created Build Tool Detection guide
- ✅ Created comprehensive Vite Migration Guide
- ✅ Added quick start examples
- ✅ Documented troubleshooting steps
All changes were committed with conventional commit messages:
feat(config): add Vite environment variable supportfeat(detector): implement build tool detection for Vite and Webpackfeat(utils): add build reporter and custom error handlingrefactor(utils): enhance logger with colored output supportfeat(config): add Vite-specific path resolution and detectionfeat(adapter): integrate build reporter into Vite adapterfeat(core): integrate build tool detection and adapter selectionbuild(deps): add Vite peer dependencies and update TypeScript supporttest: add unit tests for detector, env handling, and error utilitiesdocs: add comprehensive Vite support documentation and migration guide
User runs CLI command
↓
BuildToolDetector.detect()
↓
Check package.json + config files
↓
Return 'vite' or 'webpack'
↓
Create appropriate adapter
↓
Execute command via adapter
BaseBuildAdapter (abstract)
├── ViteAdapter
│ ├── validate()
│ ├── build()
│ └── start()
└── WebpackAdapter
├── validate() → delegates to lib/validate
├── build() → delegates to lib/build
└── start() → delegates to lib/start
- Priority System: Vite takes precedence over Webpack to support gradual migration
- Adapter Pattern: Clean separation of concerns, easy to extend
- Backward Compatibility: Webpack adapter delegates to existing code
- Automatic Detection: Zero configuration required from users
- Optional Dependencies: Vite dependencies are optional peer dependencies
With Vite support, users can expect:
- 10-50x faster dev server startup
- Near-instant HMR updates
- 20-50% faster production builds
- 10-30% smaller bundle sizes
- Integration tests for Vite workflow
- Integration tests for Webpack workflow
- Migration scenario tests
- Support for additional build tools (Parcel, Turbopack)
- Custom build configuration options
- Advanced optimization features
- Node.js: >= 12.0.0
- Catalyst CLI: >= 1.13.2
- React: >= 16
- Vite: ^4.0.0 || ^5.0.0
- Webpack: via react-scripts ^5.0.0
- TypeScript: ^3.2.1 || ^4 || ^5
The implementation successfully modernizes the Catalyst React plugin with full Vite support while maintaining complete backward compatibility with existing Webpack-based projects. The automatic detection system ensures a seamless experience for users, and the comprehensive documentation provides clear guidance for both new and migrating users.