Available on crate feature
serde only.Expand description
The Vite manifest helper (18.35.0, #94): the <script> and <link>
tags for an entry point of a frontend built by Vite,
from its .vite/manifest.json in production or from the Vite dev
server in development. serde feature.
use rust_web_server::vite::Vite;
let manifest = r#"{
"src/main.ts": {"file": "assets/main-4f2a.js", "isEntry": true, "css": ["assets/main-9c1b.css"], "imports": ["_vendor.js"]},
"_vendor.js": {"file": "assets/vendor-77aa.js"}
}"#;
let vite = Vite::from_manifest_str(manifest, "/").unwrap();
let tags = vite.tags("src/main.ts").unwrap();
assert!(tags.contains(r#"<script type="module" src="/assets/main-4f2a.js"></script>"#));
assert!(tags.contains(r#"<link rel="stylesheet" href="/assets/main-9c1b.css">"#));
assert!(tags.contains(r#"<link rel="modulepreload" href="/assets/vendor-77aa.js">"#));
let dev = Vite::dev("http://localhost:5173");
assert!(dev.tags("src/main.ts").unwrap().contains("http://localhost:5173/@vite/client"));Configure Vite with build.manifest: true; the manifest is
dist/.vite/manifest.json. Vite::from_env picks the mode:
VITE_DEV_SERVER set → dev server, else the manifest at VITE_MANIFEST
(default frontend/dist/.vite/manifest.json). install makes one
process-wide, which the vite(entry=…) template function reads.
Structs§
- Chunk
Files - A manifest chunk’s output files.
Enums§
- Vite
- The tags for a Vite build or dev server.
Functions§
- asset
Vite::asseton the installed helper;Nonebeforeinstall.- install
- Make
vitethe process-wide helper thevitetemplate function uses (installing again replaces it). - tags
Vite::tagson the installed helper;Nonebeforeinstall.