autumn_plugin_react/assets.rs
1//! The loader bundle: `assets/react-islands.js`, embedded at compile time.
2//!
3//! [`ReactPlugin`](crate::ReactPlugin) installs [`REACT_ASSETS`] through
4//! `AppBuilder::plugin_assets`. Autumn serves the file under
5//! `/static/_plugins/react/`:
6//!
7//! - at a hashed URL (`react-islands.<sha256-prefix>.js`), `immutable`;
8//! - at its plain URL (`react-islands.js`), `must-revalidate`;
9//! - with `ETag`/`304`, `Range` and a computed `sha384` SRI hash.
10
11use autumn_web::assets::PluginAssets;
12
13/// URL namespace of the loader bundle: `/static/_plugins/react/`.
14pub const ASSETS_NAMESPACE: &str = "react";
15
16/// Logical path of the loader in [`REACT_ASSETS`].
17pub const LOADER_JS: &str = "react-islands.js";
18
19/// The loader bundle. It holds one file, [`LOADER_JS`].
20///
21/// [`ReactPlugin`](crate::ReactPlugin) installs it. Use it directly only to
22/// make URLs or tags yourself:
23///
24/// ```rust
25/// use autumn_plugin_react::{LOADER_JS, REACT_ASSETS};
26///
27/// let url = REACT_ASSETS.url(LOADER_JS);
28/// assert!(url.starts_with("/static/_plugins/react/react-islands."), "{url}");
29/// assert!(REACT_ASSETS.integrity(LOADER_JS).is_some_and(|s| s.starts_with("sha384-")));
30/// ```
31///
32/// `PluginAssets::from_files` does not need the `embed-assets` feature, so
33/// the host app does not need it either.
34pub static REACT_ASSETS: PluginAssets = PluginAssets::from_files(
35 ASSETS_NAMESPACE,
36 &[(LOADER_JS, include_bytes!("../assets/react-islands.js"))],
37);