Merge branch 'master' into master

This commit is contained in:
YuKun Liu 2022-04-01 16:04:45 +08:00 committed by GitHub
commit 1017c87e9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View file

@ -10,7 +10,11 @@
<div id="main"></div>
<script type="module">
import init from "./assets/dioxus/{app_name}.js";
init("./assets/dioxus/{app_name}_bg.wasm");
init("./assets/dioxus/{app_name}_bg.wasm").then(wasm => {
if (wasm.__wbindgen_start == undefined) {
wasm.main();
}
});
</script>
{script_include}
</body>

View file

@ -35,6 +35,7 @@ impl Default for DioxusConfig {
out_dir: Some(PathBuf::from("dist")),
asset_dir: Some(PathBuf::from("public")),
tools: None,
sub_package: None,
},
web: WebConfig {
app: WebAppConfing {
@ -64,6 +65,7 @@ pub struct ApplicationConfig {
pub out_dir: Option<PathBuf>,
pub asset_dir: Option<PathBuf>,
pub tools: Option<HashMap<String, toml::Value>>
pub sub_package: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -121,7 +123,11 @@ impl CrateConfig {
pub fn new() -> Result<Self> {
let dioxus_config = DioxusConfig::load()?;
let crate_dir = crate::cargo::crate_root()?;
let crate_dir = if let Some(package) = &dioxus_config.application.sub_package {
crate::cargo::crate_root()?.join(package)
} else {
crate::cargo::crate_root()?
};
let meta = crate::cargo::Metadata::get()?;
let workspace_dir = meta.workspace_root;
let target_dir = meta.target_directory;
@ -143,9 +149,10 @@ impl CrateConfig {
// We just assume they're using a 'main.rs'
// Anyway, we've already parsed the manifest, so it should be easy to change the type
let output_filename = manifest
.lib
.as_ref()
.and_then(|lib| lib.name.clone())
.bin
.first()
.or(manifest.lib.as_ref())
.and_then(|product| product.name.clone())
.or_else(|| manifest.package.as_ref().map(|pkg| pkg.name.clone()))
.expect("No lib found from cargo metadata");
let executable = ExecutableType::Binary(output_filename);