add an option to skip assets in the CLI
This commit is contained in:
1 parent
5eca11fe3d
commit
99268acc05
8 files changed
+64
-43
No files matched your search
+21
-15
@@ -22,7 +22,7 @@ pub struct BuildResult {
|
|||||||
pub elapsed_time: u128,
|
pub elapsed_time: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
pub fn build(config: &CrateConfig, quiet: bool, skip_assets: bool) -> Result<BuildResult> {
|
||||||
// [1] Build the project with cargo, generating a wasm32-unknown-unknown target (is there a more specific, better target to leverage?)
|
// [1] Build the project with cargo, generating a wasm32-unknown-unknown target (is there a more specific, better target to leverage?)
|
||||||
// [2] Generate the appropriate build folders
|
// [2] Generate the appropriate build folders
|
||||||
// [3] Wasm-bindgen the .wasm fiile, and move it into the {builddir}/modules/xxxx/xxxx_bg.wasm
|
// [3] Wasm-bindgen the .wasm fiile, and move it into the {builddir}/modules/xxxx/xxxx_bg.wasm
|
||||||
@@ -241,7 +241,9 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process_assets(config)?;
|
if !skip_assets{
|
||||||
|
process_assets(config)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(BuildResult {
|
Ok(BuildResult {
|
||||||
warnings: warning_messages,
|
warnings: warning_messages,
|
||||||
@@ -249,7 +251,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResult> {
|
pub fn build_desktop(config: &CrateConfig, _is_serve: bool, skip_assets: bool) -> Result<BuildResult> {
|
||||||
log::info!("🚅 Running build [Desktop] command...");
|
log::info!("🚅 Running build [Desktop] command...");
|
||||||
|
|
||||||
let t_start = std::time::Instant::now();
|
let t_start = std::time::Instant::now();
|
||||||
@@ -351,10 +353,12 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect assets
|
if !skip_assets{
|
||||||
process_assets(config)?;
|
// Collect assets
|
||||||
// Create the __assets_head.html file for bundling
|
process_assets(config)?;
|
||||||
create_assets_head(config)?;
|
// Create the __assets_head.html file for bundling
|
||||||
|
create_assets_head(config)?;
|
||||||
|
}
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"🚩 Build completed: [./{}]",
|
"🚩 Build completed: [./{}]",
|
||||||
@@ -444,7 +448,7 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
|
|||||||
Ok(warning_messages)
|
Ok(warning_messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_page(config: &CrateConfig, serve: bool) -> String {
|
pub fn gen_page(config: &CrateConfig, serve: bool, skip_assets: bool) -> String {
|
||||||
let _gaurd = WebAssetConfigDropGuard::new();
|
let _gaurd = WebAssetConfigDropGuard::new();
|
||||||
|
|
||||||
let crate_root = crate::cargo::crate_root().unwrap();
|
let crate_root = crate::cargo::crate_root().unwrap();
|
||||||
@@ -461,14 +465,14 @@ pub fn gen_page(config: &CrateConfig, serve: bool) -> String {
|
|||||||
String::from(include_str!("./assets/index.html"))
|
String::from(include_str!("./assets/index.html"))
|
||||||
};
|
};
|
||||||
|
|
||||||
let resouces = config.dioxus_config.web.resource.clone();
|
let resources = config.dioxus_config.web.resource.clone();
|
||||||
|
|
||||||
let mut style_list = resouces.style.unwrap_or_default();
|
let mut style_list = resources.style.unwrap_or_default();
|
||||||
let mut script_list = resouces.script.unwrap_or_default();
|
let mut script_list = resources.script.unwrap_or_default();
|
||||||
|
|
||||||
if serve {
|
if serve {
|
||||||
let mut dev_style = resouces.dev.style.clone().unwrap_or_default();
|
let mut dev_style = resources.dev.style.clone().unwrap_or_default();
|
||||||
let mut dev_script = resouces.dev.script.unwrap_or_default();
|
let mut dev_script = resources.dev.script.unwrap_or_default();
|
||||||
style_list.append(&mut dev_style);
|
style_list.append(&mut dev_style);
|
||||||
script_list.append(&mut dev_script);
|
script_list.append(&mut dev_script);
|
||||||
}
|
}
|
||||||
@@ -490,8 +494,10 @@ pub fn gen_page(config: &CrateConfig, serve: bool) -> String {
|
|||||||
{
|
{
|
||||||
style_str.push_str("<link rel=\"stylesheet\" href=\"tailwind.css\">\n");
|
style_str.push_str("<link rel=\"stylesheet\" href=\"tailwind.css\">\n");
|
||||||
}
|
}
|
||||||
let manifest = config.asset_manifest();
|
if !skip_assets{
|
||||||
style_str.push_str(&manifest.head());
|
let manifest = config.asset_manifest();
|
||||||
|
style_str.push_str(&manifest.head());
|
||||||
|
}
|
||||||
|
|
||||||
replace_or_insert_before("{style_include}", &style_str, "</head", &mut html);
|
replace_or_insert_before("{style_include}", &style_str, "</head", &mut html);
|
||||||
|
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ impl Build {
|
|||||||
|
|
||||||
match platform {
|
match platform {
|
||||||
Platform::Web => {
|
Platform::Web => {
|
||||||
crate::builder::build(&crate_config, false)?;
|
crate::builder::build(&crate_config, false, self.build.skip_assets)?;
|
||||||
}
|
}
|
||||||
Platform::Desktop => {
|
Platform::Desktop => {
|
||||||
crate::builder::build_desktop(&crate_config, false)?;
|
crate::builder::build_desktop(&crate_config, false, self.build.skip_assets)?;
|
||||||
}
|
}
|
||||||
Platform::Fullstack => {
|
Platform::Fullstack => {
|
||||||
// Fullstack mode must be built with web configs on the desktop (server) binary as well as the web binary
|
// Fullstack mode must be built with web configs on the desktop (server) binary as well as the web binary
|
||||||
@@ -60,7 +60,7 @@ impl Build {
|
|||||||
}
|
}
|
||||||
None => web_config.features = Some(vec![web_feature]),
|
None => web_config.features = Some(vec![web_feature]),
|
||||||
};
|
};
|
||||||
crate::builder::build(&crate_config, false)?;
|
crate::builder::build(&crate_config, false, self.build.skip_assets)?;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut desktop_config = crate_config.clone();
|
let mut desktop_config = crate_config.clone();
|
||||||
@@ -72,12 +72,12 @@ impl Build {
|
|||||||
}
|
}
|
||||||
None => desktop_config.features = Some(vec![desktop_feature]),
|
None => desktop_config.features = Some(vec![desktop_feature]),
|
||||||
};
|
};
|
||||||
crate::builder::build_desktop(&desktop_config, false)?;
|
crate::builder::build_desktop(&desktop_config, false, self.build.skip_assets)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let temp = gen_page(&crate_config, false);
|
let temp = gen_page(&crate_config, false, self.build.skip_assets);
|
||||||
|
|
||||||
let mut file = std::fs::File::create(
|
let mut file = std::fs::File::create(
|
||||||
crate_config
|
crate_config
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ impl Bundle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build the desktop app
|
// build the desktop app
|
||||||
build_desktop(&crate_config, false)?;
|
build_desktop(&crate_config, false, false)?;
|
||||||
|
|
||||||
// copy the binary to the out dir
|
// copy the binary to the out dir
|
||||||
let package = crate_config.manifest.package.unwrap();
|
let package = crate_config.manifest.package.unwrap();
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ pub struct ConfigOptsBuild {
|
|||||||
#[clap(long, value_enum)]
|
#[clap(long, value_enum)]
|
||||||
pub platform: Option<Platform>,
|
pub platform: Option<Platform>,
|
||||||
|
|
||||||
|
/// Skip collecting assets from dependencies [default: false]
|
||||||
|
#[clap(long)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub skip_assets: bool,
|
||||||
|
|
||||||
/// Space separated list of features to activate
|
/// Space separated list of features to activate
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
pub features: Option<Vec<String>>,
|
pub features: Option<Vec<String>>,
|
||||||
@@ -57,6 +62,7 @@ impl From<ConfigOptsServe> for ConfigOptsBuild {
|
|||||||
features: serve.features,
|
features: serve.features,
|
||||||
client_feature: serve.client_feature,
|
client_feature: serve.client_feature,
|
||||||
server_feature: serve.server_feature,
|
server_feature: serve.server_feature,
|
||||||
|
skip_assets: serve.skip_assets,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,6 +120,11 @@ pub struct ConfigOptsServe {
|
|||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
pub features: Option<Vec<String>>,
|
pub features: Option<Vec<String>>,
|
||||||
|
|
||||||
|
/// Skip collecting assets from dependencies [default: false]
|
||||||
|
#[clap(long)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub skip_assets: bool,
|
||||||
|
|
||||||
/// The feature to use for the client in a fullstack app [default: "web"]
|
/// The feature to use for the client in a fullstack app [default: "web"]
|
||||||
#[clap(long, default_value_t = { "web".to_string() })]
|
#[clap(long, default_value_t = { "web".to_string() })]
|
||||||
pub client_feature: String,
|
pub client_feature: String,
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ impl Serve {
|
|||||||
match platform {
|
match platform {
|
||||||
cfg::Platform::Web => {
|
cfg::Platform::Web => {
|
||||||
// generate dev-index page
|
// generate dev-index page
|
||||||
Serve::regen_dev_page(&crate_config)?;
|
Serve::regen_dev_page(&crate_config, self.serve.skip_assets)?;
|
||||||
|
|
||||||
// start the develop server
|
// start the develop server
|
||||||
server::web::startup(self.serve.port, crate_config.clone(), self.serve.open)
|
server::web::startup(self.serve.port, crate_config.clone(), self.serve.open, self.serve.skip_assets)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
cfg::Platform::Desktop => {
|
cfg::Platform::Desktop => {
|
||||||
@@ -59,8 +59,8 @@ impl Serve {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn regen_dev_page(crate_config: &CrateConfig) -> Result<()> {
|
pub fn regen_dev_page(crate_config: &CrateConfig, skip_assets: bool) -> Result<()> {
|
||||||
let serve_html = gen_page(crate_config, true);
|
let serve_html = gen_page(crate_config, true, skip_assets);
|
||||||
|
|
||||||
let dist_path = crate_config.crate_dir.join(
|
let dist_path = crate_config.crate_dir.join(
|
||||||
crate_config
|
crate_config
|
||||||
|
|||||||
@@ -209,9 +209,9 @@ fn send_msg(msg: HotReloadMsg, channel: &mut impl std::io::Write) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_desktop(config: &CrateConfig) -> Result<(Child, BuildResult)> {
|
fn start_desktop(config: &CrateConfig, skip_assets: bool) -> Result<(Child, BuildResult)> {
|
||||||
// Run the desktop application
|
// Run the desktop application
|
||||||
let result = crate::builder::build_desktop(config, true)?;
|
let result = crate::builder::build_desktop(config, true, skip_assets)?;
|
||||||
|
|
||||||
match &config.executable {
|
match &config.executable {
|
||||||
crate::ExecutableType::Binary(name)
|
crate::ExecutableType::Binary(name)
|
||||||
@@ -233,11 +233,12 @@ fn start_desktop(config: &CrateConfig) -> Result<(Child, BuildResult)> {
|
|||||||
|
|
||||||
pub(crate) struct DesktopPlatform {
|
pub(crate) struct DesktopPlatform {
|
||||||
currently_running_child: Child,
|
currently_running_child: Child,
|
||||||
|
skip_assets: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Platform for DesktopPlatform {
|
impl Platform for DesktopPlatform {
|
||||||
fn start(config: &CrateConfig, _serve: &ConfigOptsServe) -> Result<Self> {
|
fn start(config: &CrateConfig,serve: &ConfigOptsServe) -> Result<Self> {
|
||||||
let (child, first_build_result) = start_desktop(config)?;
|
let (child, first_build_result) = start_desktop(config, serve.skip_assets)?;
|
||||||
|
|
||||||
log::info!("🚀 Starting development server...");
|
log::info!("🚀 Starting development server...");
|
||||||
|
|
||||||
@@ -254,12 +255,13 @@ impl Platform for DesktopPlatform {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
currently_running_child: child,
|
currently_running_child: child,
|
||||||
|
skip_assets: serve.skip_assets,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rebuild(&mut self, config: &CrateConfig) -> Result<BuildResult> {
|
fn rebuild(&mut self, config: &CrateConfig) -> Result<BuildResult> {
|
||||||
self.currently_running_child.kill()?;
|
self.currently_running_child.kill()?;
|
||||||
let (child, result) = start_desktop(config)?;
|
let (child, result) = start_desktop(config, self.skip_assets)?;
|
||||||
self.currently_running_child = child;
|
self.currently_running_child = child;
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ struct WsReloadState {
|
|||||||
update: broadcast::Sender<()>,
|
update: broadcast::Sender<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn startup(port: u16, config: CrateConfig, start_browser: bool) -> Result<()> {
|
pub async fn startup(port: u16, config: CrateConfig, start_browser: bool, skip_assets: bool) -> Result<()> {
|
||||||
// ctrl-c shutdown checker
|
// ctrl-c shutdown checker
|
||||||
let _crate_config = config.clone();
|
let _crate_config = config.clone();
|
||||||
let _ = ctrlc::set_handler(move || {
|
let _ = ctrlc::set_handler(move || {
|
||||||
@@ -59,8 +59,8 @@ pub async fn startup(port: u16, config: CrateConfig, start_browser: bool) -> Res
|
|||||||
let ip = get_ip().unwrap_or(String::from("0.0.0.0"));
|
let ip = get_ip().unwrap_or(String::from("0.0.0.0"));
|
||||||
|
|
||||||
match config.hot_reload {
|
match config.hot_reload {
|
||||||
true => serve_hot_reload(ip, port, config, start_browser).await?,
|
true => serve_hot_reload(ip, port, config, start_browser, skip_assets).await?,
|
||||||
false => serve_default(ip, port, config, start_browser).await?,
|
false => serve_default(ip, port, config, start_browser, skip_assets).await?,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -72,8 +72,9 @@ async fn serve_default(
|
|||||||
port: u16,
|
port: u16,
|
||||||
config: CrateConfig,
|
config: CrateConfig,
|
||||||
start_browser: bool,
|
start_browser: bool,
|
||||||
|
skip_assets: bool
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let first_build_result = crate::builder::build(&config, false)?;
|
let first_build_result = crate::builder::build(&config, false, skip_assets)?;
|
||||||
|
|
||||||
log::info!("🚀 Starting development server...");
|
log::info!("🚀 Starting development server...");
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ async fn serve_default(
|
|||||||
{
|
{
|
||||||
let config = config.clone();
|
let config = config.clone();
|
||||||
let reload_tx = reload_tx.clone();
|
let reload_tx = reload_tx.clone();
|
||||||
move || build(&config, &reload_tx)
|
move || build(&config, &reload_tx, skip_assets)
|
||||||
},
|
},
|
||||||
&config,
|
&config,
|
||||||
Some(WebServerInfo {
|
Some(WebServerInfo {
|
||||||
@@ -133,8 +134,9 @@ async fn serve_hot_reload(
|
|||||||
port: u16,
|
port: u16,
|
||||||
config: CrateConfig,
|
config: CrateConfig,
|
||||||
start_browser: bool,
|
start_browser: bool,
|
||||||
|
skip_assets: bool
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let first_build_result = crate::builder::build(&config, false)?;
|
let first_build_result = crate::builder::build(&config, false, skip_assets)?;
|
||||||
|
|
||||||
log::info!("🚀 Starting development server...");
|
log::info!("🚀 Starting development server...");
|
||||||
|
|
||||||
@@ -172,7 +174,7 @@ async fn serve_hot_reload(
|
|||||||
{
|
{
|
||||||
let config = config.clone();
|
let config = config.clone();
|
||||||
let reload_tx = reload_tx.clone();
|
let reload_tx = reload_tx.clone();
|
||||||
move || build(&config, &reload_tx)
|
move || build(&config, &reload_tx, skip_assets)
|
||||||
},
|
},
|
||||||
Some(WebServerInfo {
|
Some(WebServerInfo {
|
||||||
ip: ip.clone(),
|
ip: ip.clone(),
|
||||||
@@ -473,8 +475,8 @@ async fn ws_handler(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(config: &CrateConfig, reload_tx: &Sender<()>) -> Result<BuildResult> {
|
fn build(config: &CrateConfig, reload_tx: &Sender<()>, skip_assets: bool) -> Result<BuildResult> {
|
||||||
let result = builder::build(config, true)?;
|
let result = builder::build(config, true, skip_assets)?;
|
||||||
// change the websocket reload state to true;
|
// change the websocket reload state to true;
|
||||||
// the page will auto-reload.
|
// the page will auto-reload.
|
||||||
if config
|
if config
|
||||||
@@ -484,7 +486,7 @@ fn build(config: &CrateConfig, reload_tx: &Sender<()>) -> Result<BuildResult> {
|
|||||||
.reload_html
|
.reload_html
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
let _ = Serve::regen_dev_page(config);
|
let _ = Serve::regen_dev_page(config, skip_assets);
|
||||||
}
|
}
|
||||||
let _ = reload_tx.send(());
|
let _ = reload_tx.send(());
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ module.exports = defineConfig({
|
|||||||
webServer: [
|
webServer: [
|
||||||
{
|
{
|
||||||
command:
|
command:
|
||||||
"cargo run --package dioxus-playwright-liveview-test --bin dioxus-playwright-liveview-test",
|
"cargo run --package dioxus-playwright-liveview-test --bin dioxus-playwright-liveview-test --skip-assets",
|
||||||
port: 3030,
|
port: 3030,
|
||||||
timeout: 10 * 60 * 1000,
|
timeout: 10 * 60 * 1000,
|
||||||
reuseExistingServer: !process.env.CI,
|
reuseExistingServer: !process.env.CI,
|
||||||
@@ -82,7 +82,7 @@ module.exports = defineConfig({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
cwd: path.join(process.cwd(), "web"),
|
cwd: path.join(process.cwd(), "web"),
|
||||||
command: "cargo run --package dioxus-cli -- serve",
|
command: "cargo run --package dioxus-cli --release -- serve --skip-assets",
|
||||||
port: 8080,
|
port: 8080,
|
||||||
timeout: 10 * 60 * 1000,
|
timeout: 10 * 60 * 1000,
|
||||||
reuseExistingServer: !process.env.CI,
|
reuseExistingServer: !process.env.CI,
|
||||||
@@ -90,7 +90,7 @@ module.exports = defineConfig({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
cwd: path.join(process.cwd(), 'fullstack'),
|
cwd: path.join(process.cwd(), 'fullstack'),
|
||||||
command: 'cargo run --package dioxus-cli -- build --features web --release\ncargo run --release --features ssr',
|
command: 'cargo run --package dioxus-cli --release -- build --features web --release --skip-assets\ncargo run --release --features ssr',
|
||||||
port: 3333,
|
port: 3333,
|
||||||
timeout: 10 * 60 * 1000,
|
timeout: 10 * 60 * 1000,
|
||||||
reuseExistingServer: !process.env.CI,
|
reuseExistingServer: !process.env.CI,
|
||||||
|
|||||||
Reference in new issue
Block a user