vite-static 1.1.1

Embed Vite chunks into your Rust application and query them individually.
Documentation
//! Getting started example.
//!
//! There's also no yapping version at `getting-started-no-yap.rs`.
//!
//! ```shell
//! cargo run --example getting-started
//! ```

use vite_static::Manifest;

// To add vite static, we need to create struct and add `vite_static::Manifest` derive.
// `Manifest` derive macro has options, such as vite_dist, base, etc.
// Look into documentation, if you want to see all options and descriptions for them.

#[derive(Manifest)]
// ---
// Now, we need to give path to Vite project's `dist/` folder.
// You can specify relative path (relative to Cargo.toml):
#[vite_dist = "examples/vite-project/dist"]
// Or you can specify absolute path:
// #[vite_dist = "/absolute/path/to/dist"]
// Or you can use environment variables to specify path:
// #[vite_dist = "env:MY_VITE_STATIC_PATH"]
//  (BTW, `env:` syntax supports default values after vertical bar!)
//  #[vite_dist = "env:MY_VITE_STATIC_PATH|examples/vite-project/dist"]
// ---
#[cfg_attr(debug_assertions, no_embedding)]
// RECOMMENDED!
// ^ to learn more, see `options/no-embedding.rs` example
// ^ tl;dr - it will NOT embed manifest and chunks in debug builds.
// ---
#[base = "/static"]
// This option is required, because we changed base path in `vite-project/vite.config.js`.
struct MyViteStatic;

// Now we are ready to use `MyViteStatic` struct!

fn main() {
    // You can:

    // - Resolve manifest key into output filename
    //   Manifest key - is pretty name from `src/` folder (f.e. src/main.ts)
    //   Output filename - is processed file from `dist/` folder (f.e. main.SOMEHASH.js)
    let entry1_filename = MyViteStatic
        .resolve_output("src/entry1.js") // returns Option<&str>
        .expect("failed to find src/entry1.js file"); // so this is optional
    println!("src/entry1.js -> {entry1_filename}");

    // - Get chunk by output filename
    let entry1 = MyViteStatic
        .chunk(&entry1_filename)
        .expect("failed to get src/entry1.js chunk");
    assert_eq!(entry1.file, entry1_filename);

    // - Query all chunk keys.
    let chunk_keys: Vec<_> = MyViteStatic.iter_keys().collect();
    dbg!(chunk_keys);

    // - Query all chunk output filenames.
    let chunk_outputs: Vec<_> = MyViteStatic.iter_outputs().collect();
    dbg!(chunk_outputs);

    // By using `Manifest` trait, you can implement integration to _any_ framework
    // And of course, vite-static has some builtin integrations, that you can enable with feature flags
}