| Crates.io | vite-actix |
| lib.rs | vite-actix |
| version | 0.2.6 |
| created_at | 2025-01-28 14:04:59.064434+00 |
| updated_at | 2025-08-19 15:37:27.26178+00 |
| description | A library for integrating vite dev server to actix web server. |
| homepage | |
| repository | https://github.com/Drew-Chase/vite-actix |
| max_upload_size | |
| id | 1533519 |
| size | 115,614 |
Vite Actix is a library designed to enable seamless integration of the Vite development server with the Actix web framework. It provides proxying functionality to forward HTTP requests to a local Vite server during development, enabling support for features like hot module replacement (HMR), while maintaining a production-ready design for serving static files.
Development Proxy
Forwards unmatched HTTP requests to the Vite development server during development.
Hot Module Replacement
Enables fast reloads of assets and code during development, boosting productivity.
Production-Ready
Automatically serves pre-bundled assets in production without proxy overhead.
Customizable Configuration
Supports environment variables for customizing Vite integration (e.g., working directory and port).
Make sure you have the following tools installed:
Add the library to your Rust project by including it in your Cargo.toml file:
[dependencies]
vite-actix = "0.2.1"
or using git
[dependencies]
vite-actix = { git = "https://github.com/Drew-Chase/vite-actix.git" }
Follow these steps to integrate Vite with an Actix application:
Example: Configuring Your Main Actix App: Create a basic Actix application that includes Vite integration:
use actix_web::{web, App, HttpResponse, HttpServer};
use anyhow::Result;
use vite_actix::{start_vite_server, ViteAppFactory, ProxyViteOptions};
#[actix_web::main]
async fn main() -> Result<()> {
if cfg!(debug_assertions) {
// Configure Vite options using the builder pattern
ProxyViteOptions::new()
.working_directory("./examples/wwwroot") // Directory containing vite.config.(js|ts)
.port(3000) // Custom port for Vite (default is 5173)
.build()?;
}
let server = HttpServer::new(move || {
App::new()
.route("/api/", web::get().to(HttpResponse::Ok))
.configure_vite() // Enable Vite proxy during development
})
.bind("127.0.0.1:8080")?
.run();
if cfg!(debug_assertions) {
start_vite_server()?;
}
println!("Server running at http://127.0.0.1:8080/");
Ok(server.await?)
}
Run the Vite Dev Server:
vite-actix's start_vite_server function to automatically run the Vite server in development mode./assets/...) are proxied to Vite when cfg!(debug_assertions) is true.Advanced Vite Configuration Options:
// Example of additional Vite configuration options
if cfg!(debug_assertions) {
ProxyViteOptions::new()
.port(3000) // Custom Vite server port
.working_directory("./frontend") // Custom working directory
.log_level(log::Level::Info) // Configure log level
// OR disable logging entirely
// .disable_logging()
.build()?;
}
The recommended way to configure Vite integration is using the ProxyViteOptions builder pattern:
The following routes are automatically proxied to the Vite dev server during development:
/assets/... are forwarded to the Vite server./node_modules/... through Vite.Ensure that your Vite configuration is consistent with the paths and routes used by your Actix web server.
This project is licensed under the GNU General Public License v3.0.
See the LICENSE file for details.
Contributions are welcome! Please follow these steps:
git checkout -b feature-name).git commit -m "Description of changes").git push origin feature-name).See the /examples directory for sample implementations, including a fully functional integration of Vite with an Actix service.
Enjoy using Vite Actix for your next project! If you encounter any issues, feel free to open a ticket on GitHub. 🛠️