Prerequisites
- Blaxel CLI installed and authenticated with
bl login - Node.js 18 or later
@blaxel/coreinstalled in your project withnpm install @blaxel/core
1. Understand the architecture
Running Vite inside a Blaxel Sandbox requires a few adjustments:- Vite normally binds to localhost
- Blaxel exposes services through preview URLs
- Vite must accept external connections and all hosts
vite.config.ts with host: "0.0.0.0" and allowedHosts: true, then expose the Vite development server through a Blaxel preview URL.
2. Build the sandbox image
Create aDockerfile:
3. Configure Vite
Createvite.config.ts to allow external connections:
4. Create the entrypoint
Createentrypoint.sh to start the sandbox API and Vite development server:
5. Configure and deploy the image
Createblaxel.toml beside the Dockerfile:
6. Create or reuse a sandbox
7. Configure preview response headers
Vite development servers work well with permissive CORS headers when accessed through a preview URL:8. Create the preview and token
Vite runs on port5173. Create a private preview for that port:
9. Start and monitor the development server
If you do not use the entrypoint script, start Vite programmatically:10. Access the Vite application
Once the server is running, open:11. Run the complete example
Resources
Real-time previews
Configure public and private preview URLs for sandbox services.
Sandbox images
Build and manage reusable Blaxel Sandbox images.