diff --git a/src/assets/dioxus.toml b/src/assets/dioxus.toml index 717b070e2..31e306079 100644 --- a/src/assets/dioxus.toml +++ b/src/assets/dioxus.toml @@ -1,23 +1,24 @@ [application] -# App (Project) Name +# dioxus project name name = "{{project-name}}" -# Dioxus App Support Platform -# desktop, web, mobile, ssr -platforms = ["web"] +# default platfrom +# you can also use `dioxus serve/build --platform XXX` to use other platform +# value: web | desktop +default_platform = "web" # Web `build` & `serve` dist path out_dir = "dist" +# resource (static) file folder +public_dir = "public" + [web.app] # HTML title tag content title = "dioxus | ⛺" -# resource (static) file folder -public_dir = "public" - [web.watcher] watch_path = ["src"] diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index 684cec58c..bae291b7e 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -22,7 +22,15 @@ impl Build { crate_config.as_example(self.build.example.unwrap()); } - match self.build.platform.as_str() { + let platform = self.build.platform.unwrap_or_else(|| { + crate_config + .dioxus_config + .application + .default_platform + .clone() + }); + + match platform.as_str() { "web" => { crate::builder::build(&crate_config)?; } diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index ece00e07e..2271f0453 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -19,9 +19,9 @@ pub struct ConfigOptsBuild { #[structopt(long)] pub example: Option, - /// Build platform: support Web & Desktop [default: "web"] - #[structopt(long, default_value = "web")] - pub platform: String, + /// Build platform: support Web & Desktop [default: "default_platform"] + #[structopt(long)] + pub platform: Option, } #[derive(Clone, Debug, Default, Deserialize, StructOpt)] @@ -39,9 +39,9 @@ pub struct ConfigOptsServe { #[serde(default)] pub release: bool, - /// Build platform: support Web & Desktop [default: "web"] - #[structopt(long, default_value = "web")] - pub platform: String, + /// Build platform: support Web & Desktop [default: "default_platform"] + #[structopt(long)] + pub platform: Option, } /// Ensure the given value for `--public-url` is formatted correctly. diff --git a/src/cli/serve/mod.rs b/src/cli/serve/mod.rs index 8f26e0f30..ff263b6b5 100644 --- a/src/cli/serve/mod.rs +++ b/src/cli/serve/mod.rs @@ -1,5 +1,9 @@ use crate::{cfg::ConfigOptsServe, gen_page, server, CrateConfig}; -use std::{io::Write, path::PathBuf, process::{Command, Stdio}}; +use std::{ + io::Write, + path::PathBuf, + process::{Command, Stdio}, +}; use structopt::StructOpt; /// Run the WASM project on dev-server @@ -21,7 +25,15 @@ impl Serve { crate_config.as_example(self.serve.example.unwrap()); } - match self.serve.platform.as_str() { + let platform = self.serve.platform.unwrap_or_else(|| { + crate_config + .dioxus_config + .application + .default_platform + .clone() + }); + + match platform.as_str() { "web" => { crate::builder::build(&crate_config)?; } diff --git a/src/config.rs b/src/config.rs index 1151445ef..a7f5d1fec 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,7 +31,7 @@ impl Default for DioxusConfig { Self { application: ApplicationConfig { name: "dioxus".into(), - platforms: vec![String::from("web")], + default_platform: "web".to_string(), out_dir: Some(PathBuf::from("dist")), }, web: WebConfig { @@ -59,7 +59,7 @@ impl Default for DioxusConfig { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ApplicationConfig { pub name: String, - pub platforms: Vec, + pub default_platform: String, pub out_dir: Option, }