Struct xtask_wasm::DevServer
source · #[non_exhaustive]pub struct DevServer {
pub ip: IpAddr,
pub port: u16,
pub watch: Watch,
pub command: Option<Command>,
pub not_found_path: Option<PathBuf>,
}
Expand description
A simple HTTP server useful during development.
It can watch the source code for changes and restart a provided command.
Get the files at watch_path
and serve them at a given IP address
(127.0.0.1:8000 by default). An optional command can be provided to restart
the build when changes are detected.
§Usage
use std::process;
use xtask_wasm::{
anyhow::Result,
clap,
default_dist_dir,
};
#[derive(clap::Parser)]
enum Opt {
Start(xtask_wasm::DevServer),
Dist,
}
fn main() -> Result<()> {
let opt: Opt = clap::Parser::parse();
match opt {
Opt::Start(mut dev_server) => {
log::info!("Starting the development server...");
dev_server.arg("dist").start(default_dist_dir(false))?;
}
Opt::Dist => todo!("build project"),
}
Ok(())
}
Add a start
subcommand that will run cargo xtask dist
, watching for
changes in the workspace and serve the files in the default dist directory
(target/debug/dist
for non-release) at a given IP address.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.ip: IpAddr
IP address to bind. Default to 127.0.0.1
.
port: u16
Port number. Default to 8000
.
watch: Watch
§command: Option<Command>
Command executed when a change is detected.
not_found_path: Option<PathBuf>
Use another file path when the URL is not found.
Implementations§
source§impl DevServer
impl DevServer
sourcepub fn command(self, command: Command) -> Self
pub fn command(self, command: Command) -> Self
Set the command that is executed when a change is detected.
sourcepub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self
pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self
Adds an argument to pass to the command executed when changes are detected.
This will use the xtask command by default.
sourcepub fn args<I, S>(self, args: I) -> Self
pub fn args<I, S>(self, args: I) -> Self
Adds multiple arguments to pass to the command executed when changes are detected.
This will use the xtask command by default.
Trait Implementations§
source§impl Args for DevServer
impl Args for DevServer
source§fn group_id() -> Option<Id>
fn group_id() -> Option<Id>
ArgGroup::id
][crate::ArgGroup::id] for this set of argumentssource§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
source§impl FromArgMatches for DevServer
impl FromArgMatches for DevServer
source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches ) -> Result<Self, Error>
source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches ) -> Result<(), Error>
ArgMatches
to self
.source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches ) -> Result<(), Error>
ArgMatches
to self
.