add an option to skip assets in the CLI

This commit is contained in:
Evan Almloff committed 2023-08-21 16:05:25 -05:00
1 parent 5eca11fe3d
commit 99268acc05
8 files changed
+64 -43

No files matched your search

+21 -15
View File
@@ -22,7 +22,7 @@ pub struct BuildResult {
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?)
// [2] Generate the appropriate build folders
// [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 {
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...");
let t_start = std::time::Instant::now();
@@ -351,10 +353,12 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
}
}
// Collect assets
process_assets(config)?;
// Create the __assets_head.html file for bundling
create_assets_head(config)?;
if !skip_assets{
// Collect assets
process_assets(config)?;
// Create the __assets_head.html file for bundling
create_assets_head(config)?;
}
log::info!(
"🚩 Build completed: [./{}]",
@@ -444,7 +448,7 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
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 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"))
};
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 script_list = resouces.script.unwrap_or_default();
let mut style_list = resources.style.unwrap_or_default();
let mut script_list = resources.script.unwrap_or_default();
if serve {
let mut dev_style = resouces.dev.style.clone().unwrap_or_default();
let mut dev_script = resouces.dev.script.unwrap_or_default();
let mut dev_style = resources.dev.style.clone().unwrap_or_default();
let mut dev_script = resources.dev.script.unwrap_or_default();
style_list.append(&mut dev_style);
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");
}
let manifest = config.asset_manifest();
style_str.push_str(&manifest.head());
if !skip_assets{
let manifest = config.asset_manifest();
style_str.push_str(&manifest.head());
}
replace_or_insert_before("{style_include}", &style_str, "</head", &mut html);
+5 -5
View File
@@ -42,10 +42,10 @@ impl Build {
match platform {
Platform::Web => {
crate::builder::build(&crate_config, false)?;
crate::builder::build(&crate_config, false, self.build.skip_assets)?;
}
Platform::Desktop => {
crate::builder::build_desktop(&crate_config, false)?;
crate::builder::build_desktop(&crate_config, false, self.build.skip_assets)?;
}
Platform::Fullstack => {
// 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]),
};
crate::builder::build(&crate_config, false)?;
crate::builder::build(&crate_config, false, self.build.skip_assets)?;
}
{
let mut desktop_config = crate_config.clone();
@@ -72,12 +72,12 @@ impl Build {
}
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(
crate_config
+1 -1
View File
@@ -77,7 +77,7 @@ impl Bundle {
}
// build the desktop app
build_desktop(&crate_config, false)?;
build_desktop(&crate_config, false, false)?;
// copy the binary to the out dir
let package = crate_config.manifest.package.unwrap();
+11
View File
@@ -32,6 +32,11 @@ pub struct ConfigOptsBuild {
#[clap(long, value_enum)]
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
#[clap(long)]
pub features: Option<Vec<String>>,
@@ -57,6 +62,7 @@ impl From<ConfigOptsServe> for ConfigOptsBuild {
features: serve.features,
client_feature: serve.client_feature,
server_feature: serve.server_feature,
skip_assets: serve.skip_assets,
}
}
}
@@ -114,6 +120,11 @@ pub struct ConfigOptsServe {
#[clap(long)]
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"]
#[clap(long, default_value_t = { "web".to_string() })]
pub client_feature: String,
+4 -4
View File
@@ -43,10 +43,10 @@ impl Serve {
match platform {
cfg::Platform::Web => {
// generate dev-index page
Serve::regen_dev_page(&crate_config)?;
Serve::regen_dev_page(&crate_config, self.serve.skip_assets)?;
// 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?;
}
cfg::Platform::Desktop => {
@@ -59,8 +59,8 @@ impl Serve {
Ok(())
}
pub fn regen_dev_page(crate_config: &CrateConfig) -> Result<()> {
let serve_html = gen_page(crate_config, true);
pub fn regen_dev_page(crate_config: &CrateConfig, skip_assets: bool) -> Result<()> {
let serve_html = gen_page(crate_config, true, skip_assets);
let dist_path = crate_config.crate_dir.join(
crate_config
+7 -5
View File
@@ -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
let result = crate::builder::build_desktop(config, true)?;
let result = crate::builder::build_desktop(config, true, skip_assets)?;
match &config.executable {
crate::ExecutableType::Binary(name)
@@ -233,11 +233,12 @@ fn start_desktop(config: &CrateConfig) -> Result<(Child, BuildResult)> {
pub(crate) struct DesktopPlatform {
currently_running_child: Child,
skip_assets: bool,
}
impl Platform for DesktopPlatform {
fn start(config: &CrateConfig, _serve: &ConfigOptsServe) -> Result<Self> {
let (child, first_build_result) = start_desktop(config)?;
fn start(config: &CrateConfig,serve: &ConfigOptsServe) -> Result<Self> {
let (child, first_build_result) = start_desktop(config, serve.skip_assets)?;
log::info!("🚀 Starting development server...");
@@ -254,12 +255,13 @@ impl Platform for DesktopPlatform {
Ok(Self {
currently_running_child: child,
skip_assets: serve.skip_assets,
})
}
fn rebuild(&mut self, config: &CrateConfig) -> Result<BuildResult> {
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;
Ok(result)
}
+12 -10
View File
@@ -47,7 +47,7 @@ struct WsReloadState {
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
let _crate_config = config.clone();
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"));
match config.hot_reload {
true => serve_hot_reload(ip, port, config, start_browser).await?,
false => serve_default(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, skip_assets).await?,
}
Ok(())
@@ -72,8 +72,9 @@ async fn serve_default(
port: u16,
config: CrateConfig,
start_browser: bool,
skip_assets: bool
) -> 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...");
@@ -86,7 +87,7 @@ async fn serve_default(
{
let config = config.clone();
let reload_tx = reload_tx.clone();
move || build(&config, &reload_tx)
move || build(&config, &reload_tx, skip_assets)
},
&config,
Some(WebServerInfo {
@@ -133,8 +134,9 @@ async fn serve_hot_reload(
port: u16,
config: CrateConfig,
start_browser: bool,
skip_assets: bool
) -> 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...");
@@ -172,7 +174,7 @@ async fn serve_hot_reload(
{
let config = config.clone();
let reload_tx = reload_tx.clone();
move || build(&config, &reload_tx)
move || build(&config, &reload_tx, skip_assets)
},
Some(WebServerInfo {
ip: ip.clone(),
@@ -473,8 +475,8 @@ async fn ws_handler(
})
}
fn build(config: &CrateConfig, reload_tx: &Sender<()>) -> Result<BuildResult> {
let result = builder::build(config, true)?;
fn build(config: &CrateConfig, reload_tx: &Sender<()>, skip_assets: bool) -> Result<BuildResult> {
let result = builder::build(config, true, skip_assets)?;
// change the websocket reload state to true;
// the page will auto-reload.
if config
@@ -484,7 +486,7 @@ fn build(config: &CrateConfig, reload_tx: &Sender<()>) -> Result<BuildResult> {
.reload_html
.unwrap_or(false)
{
let _ = Serve::regen_dev_page(config);
let _ = Serve::regen_dev_page(config, skip_assets);
}
let _ = reload_tx.send(());
Ok(result)
+3 -3
View File
@@ -74,7 +74,7 @@ module.exports = defineConfig({
webServer: [
{
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,
timeout: 10 * 60 * 1000,
reuseExistingServer: !process.env.CI,
@@ -82,7 +82,7 @@ module.exports = defineConfig({
},
{
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,
timeout: 10 * 60 * 1000,
reuseExistingServer: !process.env.CI,
@@ -90,7 +90,7 @@ module.exports = defineConfig({
},
{
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,
timeout: 10 * 60 * 1000,
reuseExistingServer: !process.env.CI,