Преглед на файлове

Merge branch 'master' into master

YuKun Liu преди 3 години
родител
ревизия
01f623d1fd
променени са 3 файла, в които са добавени 30 реда и са изтрити 22 реда
  1. 21 20
      src/assets/index.html
  2. 6 1
      src/builder.rs
  3. 3 1
      src/config.rs

+ 21 - 20
src/assets/index.html

@@ -1,21 +1,22 @@
 <html>
-  <head>
-    <title>{app_title}</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" />
-    {style_include}
-  </head>
-  <body>
-    <div id="main"></div>
-    <script type="module">
-      import init from "./assets/dioxus/{app_name}.js";
-      init("./assets/dioxus/{app_name}_bg.wasm").then(wasm => {
-        if (wasm.__wbindgen_start == undefined) {
-          wasm.main();
-        }
-      });
-    </script>
-    {script_include}
-  </body>
-</html>
+<head>
+  <title>{app_title}</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" />
+  {style_include}
+</head>
+<body>
+  <div id="main"></div>
+  <!-- Note the usage of `type=module` here as this is an ES6 module -->
+  <script type="module">
+    import init from "{base_path}/assets/dioxus/{app_name}.js";
+    init("{base_path}/assets/dioxus/{app_name}_bg.wasm").then(wasm => {
+      if (wasm.__wbindgen_start == undefined) {
+        wasm.main();
+      }
+    });
+  </script>
+  {script_include}
+</body>
+</html>

+ 6 - 1
src/builder.rs

@@ -132,7 +132,7 @@ pub fn build(config: &CrateConfig) -> Result<()> {
             );
         }
     }
-
+  
     // this code will copy all public file to the output dir
     let copy_options = fs_extra::dir::CopyOptions {
         overwrite: true,
@@ -327,6 +327,11 @@ pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
 
     html = html.replace("{app_name}", &config.application.name);
 
+    html = match &config.web.app.base_path {
+        Some(path) => html.replace("{base_path}", path),
+        None => html.replace("{base_path}", "."),
+    };
+
     let title = config
         .web
         .app

+ 3 - 1
src/config.rs

@@ -40,11 +40,12 @@ impl Default for DioxusConfig {
             web: WebConfig {
                 app: WebAppConfing {
                     title: Some("dioxus | ⛺".into()),
+                    base_path: None,
                 },
                 watcher: WebWatcherConfing {
                     watch_path: Some(vec![PathBuf::from("src")]),
                     reload_html: Some(false),
-                    index_on_404: Some(false),
+                    index_on_404: Some(true),
                 },
                 resource: WebResourceConfing {
                     dev: WebDevResourceConfing {
@@ -79,6 +80,7 @@ pub struct WebConfig {
 #[derive(Debug, Clone, Serialize, Deserialize)]
 pub struct WebAppConfing {
     pub title: Option<String>,
+    pub base_path: Option<String>,
 }
 
 #[derive(Debug, Clone, Serialize, Deserialize)]