Răsfoiți Sursa

Merge branch 'master' into master

YuKun Liu 3 ani în urmă
părinte
comite
1017c87e9b
2 a modificat fișierele cu 16 adăugiri și 5 ștergeri
  1. 5 1
      src/assets/index.html
  2. 11 4
      src/config.rs

+ 5 - 1
src/assets/index.html

@@ -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>

+ 11 - 4
src/config.rs

@@ -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);