浏览代码

implement fullstack assets integration

Evan Almloff 1 年之前
父节点
当前提交
1c58352456
共有 3 个文件被更改,包括 12 次插入7 次删除
  1. 5 5
      packages/cli/src/builder.rs
  2. 3 1
      packages/cli/src/cli/build.rs
  3. 4 1
      packages/cli/src/server/fullstack/mod.rs

+ 5 - 5
packages/cli/src/builder.rs

@@ -40,7 +40,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
         ..
     } = config;
 
-    let _gaurd = AssetConfigDropGaurd::new();
+    let _gaurd = WebAssetConfigDropGuard::new();
 
     // start to build the assets
     let ignore_files = build_assets(config)?;
@@ -445,7 +445,7 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
 }
 
 pub fn gen_page(config: &CrateConfig, serve: bool) -> String {
-    let _gaurd = AssetConfigDropGaurd::new();
+    let _gaurd = WebAssetConfigDropGuard::new();
 
     let crate_root = crate::cargo::crate_root().unwrap();
     let custom_html_file = crate_root.join("index.html");
@@ -764,9 +764,9 @@ fn process_assets(config: &CrateConfig) -> anyhow::Result<()> {
 //     )?)
 // }
 
-struct AssetConfigDropGaurd;
+pub(crate) struct WebAssetConfigDropGuard;
 
-impl AssetConfigDropGaurd {
+impl WebAssetConfigDropGuard {
     pub fn new() -> Self {
         // Set up the collect asset config
         assets_cli_support::Config::default()
@@ -776,7 +776,7 @@ impl AssetConfigDropGaurd {
     }
 }
 
-impl Drop for AssetConfigDropGaurd {
+impl Drop for WebAssetConfigDropGuard {
     fn drop(&mut self) {
         // Reset the config
         assets_cli_support::Config::default().save();

+ 3 - 1
packages/cli/src/cli/build.rs

@@ -1,6 +1,6 @@
-use crate::cfg::Platform;
 #[cfg(feature = "plugin")]
 use crate::plugin::PluginManager;
+use crate::{cfg::Platform, WebAssetConfigDropGuard};
 
 use super::*;
 
@@ -48,6 +48,8 @@ impl Build {
                 crate::builder::build_desktop(&crate_config, false)?;
             }
             Platform::Fullstack => {
+                // Fullstack mode must be built with web configs on the desktop (server) binary as well as the web binary
+                let _config = WebAssetConfigDropGuard::new();
                 {
                     let mut web_config = crate_config.clone();
                     let web_feature = self.build.client_feature;

+ 4 - 1
packages/cli/src/server/fullstack/mod.rs

@@ -1,6 +1,6 @@
 use crate::{
     cfg::{ConfigOptsBuild, ConfigOptsServe},
-    CrateConfig, Result,
+    CrateConfig, Result, WebAssetConfigDropGuard,
 };
 
 use super::{desktop, Platform};
@@ -12,6 +12,7 @@ pub async fn startup(config: CrateConfig, serve: &ConfigOptsServe) -> Result<()>
 struct FullstackPlatform {
     serve: ConfigOptsServe,
     desktop: desktop::DesktopPlatform,
+    _config: WebAssetConfigDropGuard,
 }
 
 impl Platform for FullstackPlatform {
@@ -32,11 +33,13 @@ impl Platform for FullstackPlatform {
             }
             None => desktop_config.features = Some(vec![desktop_feature]),
         };
+        let config = WebAssetConfigDropGuard::new();
         let desktop = desktop::DesktopPlatform::start(&desktop_config, serve)?;
 
         Ok(Self {
             desktop,
             serve: serve.clone(),
+            _config: config,
         })
     }