feat: add default_platform config

This commit is contained in:
mrxiaozhuox committed 2022-02-09 21:11:41 +08:00
1 parent 1835a25e03
commit 59ebb9ec11
5 files changed
+39 -18

No files matched your search

+8 -7
View File
@@ -1,23 +1,24 @@
[application] [application]
# App (Project) Name # dioxus project name
name = "{{project-name}}" name = "{{project-name}}"
# Dioxus App Support Platform # default platfrom
# desktop, web, mobile, ssr # you can also use `dioxus serve/build --platform XXX` to use other platform
platforms = ["web"] # value: web | desktop
default_platform = "web"
# Web `build` & `serve` dist path # Web `build` & `serve` dist path
out_dir = "dist" out_dir = "dist"
# resource (static) file folder
public_dir = "public"
[web.app] [web.app]
# HTML title tag content # HTML title tag content
title = "dioxus | ⛺" title = "dioxus | ⛺"
# resource (static) file folder
public_dir = "public"
[web.watcher] [web.watcher]
watch_path = ["src"] watch_path = ["src"]
+9 -1
View File
@@ -22,7 +22,15 @@ impl Build {
crate_config.as_example(self.build.example.unwrap()); 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" => { "web" => {
crate::builder::build(&crate_config)?; crate::builder::build(&crate_config)?;
} }
+6 -6
View File
@@ -19,9 +19,9 @@ pub struct ConfigOptsBuild {
#[structopt(long)] #[structopt(long)]
pub example: Option<String>, pub example: Option<String>,
/// Build platform: support Web & Desktop [default: "web"] /// Build platform: support Web & Desktop [default: "default_platform"]
#[structopt(long, default_value = "web")] #[structopt(long)]
pub platform: String, pub platform: Option<String>,
} }
#[derive(Clone, Debug, Default, Deserialize, StructOpt)] #[derive(Clone, Debug, Default, Deserialize, StructOpt)]
@@ -39,9 +39,9 @@ pub struct ConfigOptsServe {
#[serde(default)] #[serde(default)]
pub release: bool, pub release: bool,
/// Build platform: support Web & Desktop [default: "web"] /// Build platform: support Web & Desktop [default: "default_platform"]
#[structopt(long, default_value = "web")] #[structopt(long)]
pub platform: String, pub platform: Option<String>,
} }
/// Ensure the given value for `--public-url` is formatted correctly. /// Ensure the given value for `--public-url` is formatted correctly.
+14 -2
View File
@@ -1,5 +1,9 @@
use crate::{cfg::ConfigOptsServe, gen_page, server, CrateConfig}; 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; use structopt::StructOpt;
/// Run the WASM project on dev-server /// Run the WASM project on dev-server
@@ -21,7 +25,15 @@ impl Serve {
crate_config.as_example(self.serve.example.unwrap()); 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" => { "web" => {
crate::builder::build(&crate_config)?; crate::builder::build(&crate_config)?;
} }
+2 -2
View File
@@ -31,7 +31,7 @@ impl Default for DioxusConfig {
Self { Self {
application: ApplicationConfig { application: ApplicationConfig {
name: "dioxus".into(), name: "dioxus".into(),
platforms: vec![String::from("web")], default_platform: "web".to_string(),
out_dir: Some(PathBuf::from("dist")), out_dir: Some(PathBuf::from("dist")),
}, },
web: WebConfig { web: WebConfig {
@@ -59,7 +59,7 @@ impl Default for DioxusConfig {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApplicationConfig { pub struct ApplicationConfig {
pub name: String, pub name: String,
pub platforms: Vec<String>, pub default_platform: String,
pub out_dir: Option<PathBuf>, pub out_dir: Option<PathBuf>,
} }