set the required environment variable for manganis support

This commit is contained in:
Evan Almloff committed 2024-01-10 11:19:51 -06:00
1 parent 663296ae45
commit e004c1722f
20 files changed
+99 -190

No files matched your search

-3
View File
@@ -67,9 +67,6 @@ dioxus-hot-reload = { workspace = true }
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3.61", features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] }
[target.'cfg(any(target_os = "windows",target_os = "macos",target_os = "linux",target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
# This is only for debug mode, and it appears mobile does not support some packages this uses
manganis-cli-support = { workspace = true, features = ["webp", "html"] }
[features]
default = ["hot-reload"]
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>dioxus | ⛺</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8" />
</head>
<body>
<div id="main"></div>
<script type="module">
import init from "/./assets/dioxus/name.js";
init("/./assets/dioxus/name_bg.wasm").then(wasm => {
if (wasm.__wbindgen_start == undefined) {
wasm.main();
}
});
</script>
</body>
</html><script>// Dioxus-CLI
// https://github.com/DioxusLabs/dioxus/tree/master/packages/cli
(function () {
var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
var url = protocol + '//' + window.location.host + '/_dioxus/ws';
var poll_interval = 8080;
var reload_upon_connect = () => {
window.setTimeout(
() => {
var ws = new WebSocket(url);
ws.onopen = () => window.location.reload();
ws.onclose = reload_upon_connect;
},
poll_interval);
};
var ws = new WebSocket(url);
ws.onmessage = (ev) => {
if (ev.data == "reload") {
window.location.reload();
}
};
ws.onclose = reload_upon_connect;
})()
</script>
@@ -276,9 +276,6 @@ where
fn serve_static_assets(mut self, assets_path: impl Into<std::path::PathBuf>) -> Self {
use tower_http::services::{ServeDir, ServeFile};
// Copy over any assets we find
crate::collect_assets::copy_assets();
let assets_path = assets_path.into();
// Serve all files in dist folder except index.html
@@ -241,9 +241,6 @@ impl DioxusRouterExt for Router {
}
fn serve_static_assets(mut self, assets_path: impl Into<std::path::PathBuf>) -> Self {
// Copy over any assets we find
crate::collect_assets::copy_assets();
let assets_path = assets_path.into();
// Serve all files in dist folder except index.html
@@ -187,9 +187,6 @@ pub fn serve_dioxus_application<P: Clone + serde::Serialize + Send + Sync + 'sta
// Serve the dist folder and the index.html file
let serve_dir = warp::fs::dir(cfg.assets_path);
// Copy over any assets we find
crate::collect_assets::copy_assets();
connect_hot_reload()
// First register the server functions
.or(register_server_fns(server_fn_route))
-61
View File
@@ -1,61 +0,0 @@
#[cfg(any(feature = "axum", feature = "warp", feature = "salvo"))]
pub fn copy_assets() {
#[cfg(all(
debug_assertions,
any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
)
))]
{
// The CLI will copy assets to the current working directory
if std::env::var_os("DIOXUS_ACTIVE").is_some() {
return;
}
use manganis_cli_support::AssetManifest;
use manganis_cli_support::AssetManifestExt;
use manganis_cli_support::Config;
use std::path::PathBuf;
let config = Config::current();
let asset_location = config.assets_serve_location();
let asset_location = PathBuf::from(asset_location);
let _ = std::fs::remove_dir_all(&asset_location);
println!("Finding assets... (Note: if you run a dioxus desktop application with the CLI. This process will be significantly faster.)");
let manifest = AssetManifest::load();
let has_assets = manifest
.packages()
.iter()
.any(|package| !package.assets().is_empty());
if has_assets {
println!("Copying and optimizing assets...");
manifest.copy_static_assets_to(&asset_location).unwrap();
println!("Copied assets to {}", asset_location.display());
} else {
println!("No assets found");
}
}
#[cfg(not(all(
debug_assertions,
any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
)
)))]
{
println!(
"Skipping assets in release mode. You compile assets with the dioxus-cli in release mode"
);
}
}
-1
View File
@@ -14,7 +14,6 @@ pub mod router;
mod adapters;
#[cfg(feature = "ssr")]
pub use adapters::*;
mod collect_assets;
mod hooks;
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
mod hot_reload;