Skip to content

Commit

Permalink
feat(cli/dev): add --no-dev-server, ref #5708 (#5722)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Nov 30, 2022
1 parent 04681a6 commit c098984
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changes/cli-no-dev-server.md
@@ -0,0 +1,5 @@
---
"cli.rs": "patch"
---

Add `--no-dev-server` flag to the cli to disable the dev server for static files in dev mode.
47 changes: 26 additions & 21 deletions tooling/cli/src/dev.rs
Expand Up @@ -61,6 +61,9 @@ pub struct Options {
/// Disable the file watcher
#[clap(long)]
pub no_watch: bool,
/// Disable the dev server for static files.
#[clap(long)]
pub no_dev_server: bool,
}

pub fn command(options: Options) -> Result<()> {
Expand Down Expand Up @@ -218,31 +221,33 @@ fn command_internal(mut options: Options) -> Result<()> {
.build
.dev_path
.clone();
if let AppUrl::Url(WindowUrl::App(path)) = &dev_path {
use crate::helpers::web_dev_server::{start_dev_server, SERVER_URL};
if path.exists() {
let path = path.canonicalize()?;
start_dev_server(path);
dev_path = AppUrl::Url(WindowUrl::External(SERVER_URL.parse().unwrap()));
if !options.no_dev_server {
if let AppUrl::Url(WindowUrl::App(path)) = &dev_path {
use crate::helpers::web_dev_server::{start_dev_server, SERVER_URL};
if path.exists() {
let path = path.canonicalize()?;
start_dev_server(path);
dev_path = AppUrl::Url(WindowUrl::External(SERVER_URL.parse().unwrap()));

// TODO: in v2, use an env var to pass the url to the app context
// or better separate the config passed from the cli internally and
// config passed by the user in `--config` into to separate env vars
// and the context merges, the user first, then the internal cli config
if let Some(c) = options.config {
let mut c: tauri_utils::config::Config = serde_json::from_str(&c)?;
c.build.dev_path = dev_path.clone();
options.config = Some(serde_json::to_string(&c).unwrap());
} else {
options.config = Some(format!(
r#"{{ "build": {{ "devPath": "{}" }} }}"#,
SERVER_URL
))
// TODO: in v2, use an env var to pass the url to the app context
// or better separate the config passed from the cli internally and
// config passed by the user in `--config` into to separate env vars
// and the context merges, the user first, then the internal cli config
if let Some(c) = options.config {
let mut c: tauri_utils::config::Config = serde_json::from_str(&c)?;
c.build.dev_path = dev_path.clone();
options.config = Some(serde_json::to_string(&c).unwrap());
} else {
options.config = Some(format!(
r#"{{ "build": {{ "devPath": "{}" }} }}"#,
SERVER_URL
))
}
}
}
}

reload_config(options.config.as_deref())?;
reload_config(options.config.as_deref())?;
}

if std::env::var_os("TAURI_SKIP_DEVSERVER_CHECK") != Some("true".into()) {
if let AppUrl::Url(WindowUrl::External(dev_server_url)) = dev_path {
Expand Down

0 comments on commit c098984

Please sign in to comment.