The Vite Config Manager module is responsible for updating the Vite configuration file to include the auto-import plugins. It provides functions to locate, parse, and modify the Vite configuration file to enable automatic component and API imports.
updateViteConfig
Signature:
Parameters:
options: UpdateViteConfigOptions
- Configuration options for Vite config update
path?: string
- The path to the project directory (defaults to current directory)library: string
- The component library to configureviteConfigPath?: string
- The path to the Vite configuration file (auto-detected if not specified)Returns:
Promise<UpdateViteConfigResult>
- A promise that resolves to the update result
success: boolean
- Whether the update was successfulviteConfigPath: string
- The path to the updated Vite configuration fileconfigUpdated: boolean
- Whether the configuration was actually modifiedExample:
The Vite Config Manager performs the following operations:
Configuration File Detection
AST Parsing and Transformation
Code Generation
The module adds different resolver configurations based on the selected component library:
The Vite Config Manager uses AST manipulation libraries to modify the configuration file. It follows these steps:
The Vite Config Manager includes robust error handling to provide clear feedback when issues are encountered:
These errors are propagated to the caller with descriptive messages to help users troubleshoot issues.