在安装到主机应用程序时,加载Micro Frontend root App组件在单打序列中的CSS组件

发布于 2025-01-28 08:42:19 字数 940 浏览 3 评论 0原文

同事!

需要一个建议! SinglesPareact中的Micro Frontend不会在安装上加载root的组件CSS,而只能根据路由导航页面CSS。

使用单打序列实现了微观前端。在WebPack.config中用于DevMode构建使用:

plugins: [
  new MiniCssExtractPlugin({
    filename: '[name].[contenthash].css',
    ignoreOrder: false,

  }),
  new ExposeRuntimeCssAssetsPlugin({
    filename: '[name].[contenthash].css',
  }),
],

我们使用CSS模块。 将我们的微型前端安装到主机应用程序时,已经遇到了问题:它不会加载root App组件的CSS。仅加载它通过路由导航到的页面。我们的切入点看起来像:

 const lifecycles = singleSpaReact({
  React,
  ReactDOM,
  rootComponent: App,
  errorBoundary(err, info, props) {
    return GlobalErrorBoundary
  },
})

export const { bootstrap, mount, unmount } = lifecycles

因此,root React组件是应用程序。它在每个组件中呈现一个带有某些CSS模块的组件树,但是CSS并未加载。我检查了如何在主机应用中应用CSS:它通过路由在导航时将页面CSS的“链接”标签添加到头部。 在我们的构建中有什么问题,可能会添加哪些额外的步骤来解决问题,即使“应用” root组件的CSS加载? 非常感谢任何线索!

colleagues!

Need a piece of advice! Micro frontend in singleSpaReact does not load root's component CSS at the mounting, but only page CSS according routing navigation.

Implemented a micro frontend using singleSpaReact. In webpack.config for devmode build use:

plugins: [
  new MiniCssExtractPlugin({
    filename: '[name].[contenthash].css',
    ignoreOrder: false,

  }),
  new ExposeRuntimeCssAssetsPlugin({
    filename: '[name].[contenthash].css',
  }),
],

We use CSS-modules.
Have been running into an issue on mounting our micro front end to the host application: it does not load root App component's CSS. Only loads CSS for a page it navigates to via routing. Our entry point looks like:

 const lifecycles = singleSpaReact({
  React,
  ReactDOM,
  rootComponent: App,
  errorBoundary(err, info, props) {
    return GlobalErrorBoundary
  },
})

export const { bootstrap, mount, unmount } = lifecycles

So, the root React component is App. It renders a tree of components with some CSS modules in each one, but the CSS is not loaded. I checked how the CSS is applied in our host app: it adds "link" tag for pages's CSS into the head on navigation via routing.
What's wrong in our build, what extra steps might be added to address the issue, I.e. to make "App" root component's CSS loaded?
Highly appreciate any clue!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫南 2025-02-04 08:42:19

已经通过添加SinglesPacss模块解决了。

    
        const reactLifecycles = singleSpaReact({
          React,
          ReactDOM,
          rootComponent: App,
          errorBoundary(err, info, props) {
            return GlobalErrorBoundary
          },
        })
        
        const cssLifecycles =
          !getIsDevelopment() &&
          singleSpaCss({
            // cssUrls: [],
            webpackExtractedCss: true,
            shouldUnmount: true,
            timeout: 5000,
          })
        
        let bootstrap
        let mount
        let unmount
        
        if (getIsDevelopment()) {
          bootstrap = reactLifecycles.bootstrap
          mount = reactLifecycles.mount
          unmount = reactLifecycles.unmount
        } else {
          bootstrap = [cssLifecycles.bootstrap, reactLifecycles.bootstrap]
        
          mount = [
            // The css lifecycles should be before your framework's mount lifecycle,
            // to avoid a Flicker of Unstyled Content (FOUC)
            cssLifecycles.mount,
            reactLifecycles.mount,
          ]
        
          unmount = [
            // The css lifecycles should be after your framework's unmount lifecycle,
            // to avoid a Flicker of Unstyled Content (FOUC)
            reactLifecycles.unmount,
            cssLifecycles.unmount,
          ]
        }
        
        export { bootstrap, mount, unmount }
    
    


Already solved by means of adding singleSpaCss module.

    
        const reactLifecycles = singleSpaReact({
          React,
          ReactDOM,
          rootComponent: App,
          errorBoundary(err, info, props) {
            return GlobalErrorBoundary
          },
        })
        
        const cssLifecycles =
          !getIsDevelopment() &&
          singleSpaCss({
            // cssUrls: [],
            webpackExtractedCss: true,
            shouldUnmount: true,
            timeout: 5000,
          })
        
        let bootstrap
        let mount
        let unmount
        
        if (getIsDevelopment()) {
          bootstrap = reactLifecycles.bootstrap
          mount = reactLifecycles.mount
          unmount = reactLifecycles.unmount
        } else {
          bootstrap = [cssLifecycles.bootstrap, reactLifecycles.bootstrap]
        
          mount = [
            // The css lifecycles should be before your framework's mount lifecycle,
            // to avoid a Flicker of Unstyled Content (FOUC)
            cssLifecycles.mount,
            reactLifecycles.mount,
          ]
        
          unmount = [
            // The css lifecycles should be after your framework's unmount lifecycle,
            // to avoid a Flicker of Unstyled Content (FOUC)
            reactLifecycles.unmount,
            cssLifecycles.unmount,
          ]
        }
        
        export { bootstrap, mount, unmount }
    
    

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文