Skip to content

Commit c098984

Browse files
authored
feat(cli/dev): add --no-dev-server, ref #5708 (#5722)
1 parent 04681a6 commit c098984

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

.changes/cli-no-dev-server.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": "patch"
3+
---
4+
5+
Add `--no-dev-server` flag to the cli to disable the dev server for static files in dev mode.

tooling/cli/src/dev.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub struct Options {
6161
/// Disable the file watcher
6262
#[clap(long)]
6363
pub no_watch: bool,
64+
/// Disable the dev server for static files.
65+
#[clap(long)]
66+
pub no_dev_server: bool,
6467
}
6568

6669
pub fn command(options: Options) -> Result<()> {
@@ -218,31 +221,33 @@ fn command_internal(mut options: Options) -> Result<()> {
218221
.build
219222
.dev_path
220223
.clone();
221-
if let AppUrl::Url(WindowUrl::App(path)) = &dev_path {
222-
use crate::helpers::web_dev_server::{start_dev_server, SERVER_URL};
223-
if path.exists() {
224-
let path = path.canonicalize()?;
225-
start_dev_server(path);
226-
dev_path = AppUrl::Url(WindowUrl::External(SERVER_URL.parse().unwrap()));
224+
if !options.no_dev_server {
225+
if let AppUrl::Url(WindowUrl::App(path)) = &dev_path {
226+
use crate::helpers::web_dev_server::{start_dev_server, SERVER_URL};
227+
if path.exists() {
228+
let path = path.canonicalize()?;
229+
start_dev_server(path);
230+
dev_path = AppUrl::Url(WindowUrl::External(SERVER_URL.parse().unwrap()));
227231

228-
// TODO: in v2, use an env var to pass the url to the app context
229-
// or better separate the config passed from the cli internally and
230-
// config passed by the user in `--config` into to separate env vars
231-
// and the context merges, the user first, then the internal cli config
232-
if let Some(c) = options.config {
233-
let mut c: tauri_utils::config::Config = serde_json::from_str(&c)?;
234-
c.build.dev_path = dev_path.clone();
235-
options.config = Some(serde_json::to_string(&c).unwrap());
236-
} else {
237-
options.config = Some(format!(
238-
r#"{{ "build": {{ "devPath": "{}" }} }}"#,
239-
SERVER_URL
240-
))
232+
// TODO: in v2, use an env var to pass the url to the app context
233+
// or better separate the config passed from the cli internally and
234+
// config passed by the user in `--config` into to separate env vars
235+
// and the context merges, the user first, then the internal cli config
236+
if let Some(c) = options.config {
237+
let mut c: tauri_utils::config::Config = serde_json::from_str(&c)?;
238+
c.build.dev_path = dev_path.clone();
239+
options.config = Some(serde_json::to_string(&c).unwrap());
240+
} else {
241+
options.config = Some(format!(
242+
r#"{{ "build": {{ "devPath": "{}" }} }}"#,
243+
SERVER_URL
244+
))
245+
}
241246
}
242247
}
243-
}
244248

245-
reload_config(options.config.as_deref())?;
249+
reload_config(options.config.as_deref())?;
250+
}
246251

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

0 commit comments

Comments
 (0)