Build Extensions
Rspress provides a powerful build extension system that allows you to customize and enhance the build process of your documentation site. This chapter explores how to use plugins, custom build configurations, and advanced features to extend Rspress.
Extension System Overview
What are Build Extensions?
Build extensions allow you to:
- Add Features: Extend core functionality through plugins
- Customize Build: Modify the build process
- Integrate Tools: Connect external tools and services
- Optimize Output: Enhance build output
Extension Types
Plugin System:
- Official plugins
- Community plugins
- Custom plugins
Build Configuration:
- Vite configuration
- Rsbuild configuration
- Custom transformations
Plugin System
Using Plugins
Add plugins in your configuration:
Official Plugins
Sitemap Plugin
Generate XML sitemap:
RSS Plugin
Generate RSS feed:
Preview Plugin
Add code preview functionality:
Search Plugin
Enhanced search capabilities:
Creating Custom Plugins
Plugin Structure
Create a custom plugin:
Real Example: Reading Time Plugin
Create a plugin that estimates reading time:
Use the plugin:
Display in page:
Real Example: TOC Generator Plugin
Generate table of contents:
Real Example: Markdown Enhancement Plugin
Add custom Markdown syntax:
Usage:
Build Configuration
Vite Configuration
Customize Vite build:
Rsbuild Configuration
Use Rsbuild for advanced builds:
Asset Processing
Image Optimization
Optimize image assets:
Font Optimization
Optimize font loading:
Code Transformations
Babel Plugins
Add Babel transformations:
PostCSS Plugins
Add PostCSS processing:
Environment Variables
Define Variables
Define variables in build:
Use variables:
Environment Files
Use .env files:
Access them:
Build Hooks
Lifecycle Hooks
Use build lifecycle hooks:
Best Practices
Plugin Development
- Naming Conventions
- Error Handling
- Performance
Build Optimization
- Code Splitting
- Asset Compression
- Cache Optimization
Troubleshooting
Plugin Not Working
Issue: Plugin not executing
Check:
- Plugin imported correctly
- Plugin added to config
- Hook names correct
- Returning correct values
Build Errors
Issue: Build failing
Debug:
Performance Issues
Issue: Slow build
Optimize:
- Enable caching
- Reduce file watching
- Optimize plugins
- Use parallel processing
Next Steps
- Explore Custom Search
- Learn about Custom Theme
- Read about Deployment strategies
::: tip Best Practices
- Keep plugins simple and focused
- Use TypeScript for type safety
- Test plugins thoroughly
- Document plugin options
- Handle errors gracefully :::
::: warning Performance
- Avoid expensive operations in hot paths
- Use caching where appropriate
- Minimize file system operations
- Use async operations
- Monitor build times :::
::: info Resources