feat: add public_dir for other platform
This commit is contained in:
1 parent
653ee254c0
commit
9d8b95dfc4
2 files changed
+33
-4
No files matched your search
+30
-1
@@ -91,6 +91,7 @@ pub fn build(config: &CrateConfig) -> Result<()> {
|
||||
.out_name(&dioxus_config.application.name)
|
||||
.generate(&bindgen_outdir)?;
|
||||
|
||||
// this code will copy all public file to the output dir
|
||||
let copy_options = fs_extra::dir::CopyOptions {
|
||||
overwrite: true,
|
||||
skip_exist: false,
|
||||
@@ -183,9 +184,37 @@ pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> {
|
||||
file_name
|
||||
};
|
||||
|
||||
create_dir_all(&config.out_dir)?;
|
||||
if !config.out_dir.is_dir() {
|
||||
create_dir_all(&config.out_dir)?;
|
||||
}
|
||||
copy(res_path, &config.out_dir.join(target_file))?;
|
||||
|
||||
// this code will copy all public file to the output dir
|
||||
if config.public_dir.is_dir() {
|
||||
let copy_options = fs_extra::dir::CopyOptions {
|
||||
overwrite: true,
|
||||
skip_exist: false,
|
||||
buffer_size: 64000,
|
||||
copy_inside: false,
|
||||
content_only: false,
|
||||
depth: 0,
|
||||
};
|
||||
|
||||
for entry in std::fs::read_dir(&config.public_dir)? {
|
||||
let path = entry?.path();
|
||||
if path.is_file() {
|
||||
std::fs::copy(&path, &config.out_dir.join(path.file_name().unwrap()))?;
|
||||
} else {
|
||||
match fs_extra::dir::copy(&path, &config.out_dir, ©_options) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
log::warn!("Error copying dir: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log::info!(
|
||||
"🚩 Build completed: [./{}]",
|
||||
config
|
||||
|
||||
+3
-3
@@ -33,11 +33,11 @@ impl Default for DioxusConfig {
|
||||
name: "dioxus".into(),
|
||||
default_platform: "web".to_string(),
|
||||
out_dir: Some(PathBuf::from("dist")),
|
||||
public_dir: Some(PathBuf::from("public")),
|
||||
},
|
||||
web: WebConfig {
|
||||
app: WebAppConfing {
|
||||
title: Some("dioxus | ⛺".into()),
|
||||
public_dir: Some(PathBuf::from("public")),
|
||||
},
|
||||
watcher: WebWatcherConfing {
|
||||
watch_path: Some(vec![PathBuf::from("src")]),
|
||||
@@ -61,6 +61,7 @@ pub struct ApplicationConfig {
|
||||
pub name: String,
|
||||
pub default_platform: String,
|
||||
pub out_dir: Option<PathBuf>,
|
||||
pub public_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -73,7 +74,6 @@ pub struct WebConfig {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebAppConfing {
|
||||
pub title: Option<String>,
|
||||
pub public_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -130,7 +130,7 @@ impl CrateConfig {
|
||||
|
||||
let cargo_def = &crate_dir.join("Cargo.toml");
|
||||
|
||||
let public_dir = match dioxus_config.web.app.public_dir {
|
||||
let public_dir = match dioxus_config.application.public_dir {
|
||||
Some(ref v) => crate_dir.join(v),
|
||||
None => crate_dir.join("public"),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user