mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-17 06:08:26 +00:00
feat: add dioxus.toml
support
This commit is contained in:
parent
5395e7693c
commit
70adff7e44
5 changed files with 98 additions and 22 deletions
|
@ -16,6 +16,7 @@ wasm-bindgen-cli-support = "0.2.79"
|
|||
anyhow = "1.0.38"
|
||||
serde = { version = "1.0.133", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
toml = "0.5.8"
|
||||
fs_extra = "1.2.0"
|
||||
cargo_toml = "0.10.0"
|
||||
futures = "0.3.12"
|
||||
|
|
42
Dioxus.toml
Normal file
42
Dioxus.toml
Normal file
|
@ -0,0 +1,42 @@
|
|||
[application]
|
||||
|
||||
# App (Project) Name
|
||||
name = "dioxus-cli"
|
||||
|
||||
# Dioxus App Support Platform
|
||||
# desktop, web, mobile, ssr
|
||||
platforms = ["web"]
|
||||
|
||||
[web.app]
|
||||
|
||||
# Web `build` & `serve` dist path
|
||||
out_dir = "dist"
|
||||
|
||||
# resource (static) file folder
|
||||
static_dir = "static"
|
||||
|
||||
[web.watcher]
|
||||
|
||||
|
||||
watch_path = ["src"]
|
||||
|
||||
# include `assets` in web platform
|
||||
[web.resource]
|
||||
|
||||
# CSS style file
|
||||
style = [
|
||||
"./my-style.css"
|
||||
]
|
||||
|
||||
# Javascript code file
|
||||
script = [
|
||||
"./app.js"
|
||||
]
|
||||
|
||||
[web.resource.dev]
|
||||
|
||||
# Javascript code file
|
||||
# serve: [dev-server] only
|
||||
script = [
|
||||
"./debug.js"
|
||||
]
|
|
@ -48,14 +48,12 @@ pub fn build(config: &CrateConfig, dist: PathBuf) -> Result<()> {
|
|||
|
||||
let output = cmd.output()?;
|
||||
|
||||
if output.status.success() {
|
||||
std::io::stdout().write_all(&output.stdout).unwrap();
|
||||
} else {
|
||||
if !output.status.success() {
|
||||
log::error!("Build failed!");
|
||||
let reason = String::from_utf8_lossy(&output.stderr).to_string();
|
||||
return Err(Error::BuildFailed(reason));
|
||||
}
|
||||
|
||||
|
||||
// [2] Establish the output directory structure
|
||||
let bindgen_outdir = out_dir.join("assets");
|
||||
|
||||
|
@ -88,13 +86,6 @@ pub fn build(config: &CrateConfig, dist: PathBuf) -> Result<()> {
|
|||
.out_name("module")
|
||||
.generate(&bindgen_outdir)?;
|
||||
|
||||
// [4]
|
||||
// TODO: wasm-opt
|
||||
|
||||
// [5] Generate the html file with the module name
|
||||
// TODO: support names via options
|
||||
|
||||
// log::info!("Writing to '{:#?}' directory...", out_dir);
|
||||
let copy_options = fs_extra::dir::CopyOptions::new();
|
||||
if static_dir.is_dir() {
|
||||
match fs_extra::dir::copy(static_dir, out_dir, ©_options) {
|
||||
|
|
|
@ -1,6 +1,44 @@
|
|||
use crate::error::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DioxusConfig {
|
||||
application: ApplicationConfig,
|
||||
web: WebConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ApplicationConfig {
|
||||
name: String,
|
||||
platform: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebConfig {
|
||||
app: WebAppConfing,
|
||||
watcher: WebWatcherConfing,
|
||||
resource: WebResourceConfing,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebAppConfing {
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebWatcherConfing {
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebResourceConfing {
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CrateConfig {
|
||||
pub out_dir: PathBuf,
|
||||
|
@ -86,4 +124,4 @@ impl CrateConfig {
|
|||
// self.release = options.release;
|
||||
// self.out_dir = tempfile::Builder::new().tempdir().expect("").into_path();
|
||||
// }
|
||||
}
|
||||
}
|
|
@ -33,6 +33,8 @@ pub async fn startup(
|
|||
|
||||
let (tx, rx) = channel();
|
||||
|
||||
let dist_path = opts.dist.clone().unwrap_or(PathBuf::from("dist"));
|
||||
|
||||
// file watcher: check file change
|
||||
let mut watcher = watcher(tx, Duration::from_secs(2)).unwrap();
|
||||
watcher
|
||||
|
@ -46,7 +48,7 @@ pub async fn startup(
|
|||
|
||||
let watcher_conf = config.clone();
|
||||
let watcher_ws_state = ws_reload_state.clone();
|
||||
let dist_path = opts.dist.clone().unwrap_or(PathBuf::from("dist"));
|
||||
let watcher_dist_path = dist_path.clone();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
if let Ok(v) = rx.recv() {
|
||||
|
@ -55,7 +57,7 @@ pub async fn startup(
|
|||
| DebouncedEvent::Write(_)
|
||||
| DebouncedEvent::Remove(_)
|
||||
| DebouncedEvent::Rename(_, _) => {
|
||||
if let Ok(_) = builder::build(&watcher_conf, dist_path.clone()) {
|
||||
if let Ok(_) = builder::build(&watcher_conf, watcher_dist_path.clone()) {
|
||||
// change the websocket reload state to true;
|
||||
// the page will auto-reload.
|
||||
watcher_ws_state.lock().unwrap().change();
|
||||
|
@ -69,14 +71,16 @@ pub async fn startup(
|
|||
|
||||
let app = Router::new()
|
||||
.route("/ws", get(ws_handler))
|
||||
.fallback(get_service(ServeDir::new(config.out_dir)).handle_error(
|
||||
|error: std::io::Error| async move {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
format!("Unhandled internal error: {}", error),
|
||||
)
|
||||
},
|
||||
))
|
||||
.fallback(
|
||||
get_service(ServeDir::new(config.crate_dir.join(&dist_path))).handle_error(
|
||||
|error: std::io::Error| async move {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
format!("Unhandled internal error: {}", error),
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
.layer(AddExtensionLayer::new(ws_reload_state.clone()));
|
||||
|
||||
// start serve dev-server at 0.0.0.0:8080
|
||||
|
|
Loading…
Add table
Reference in a new issue