alibaba / ice

🚀 ice.js: The Progressive App Framework Based On React(基于 React 的渐进式应用框架)
https://ice.work
MIT License
17.8k stars 2.09k forks source link

Optimize server compilation of routes config #6857

Open ClarkXia opened 3 months ago

ClarkXia commented 3 months ago

Summary | 概述

No response

Motivation | 背景

The framework will analyze all route components and retrieve the pageConfigexport, regardless of whether the application is configured as SPA. The purpose of extracting pageConfig from each route component is to modify the initial HTML generated by the document, including elements like title and meta.

However, when it comes to SPA configurations, updating the initial HTML with pageConfig isn't necessary, as there is often a separate server dedicated to serving HTML. Additionally, the compilation process for pageConfig tends to result in errors due to certain pieces of code and dependencies that are incompatible with Node.js.

Furthermore, this additional compilation step can significantly hinder the development velocity of the framework by introducing extra complexity and processing time.

Usage example | 使用示例

No response

Detailed design | 方案设计

The compilation step for routes-config.bundle.mjs will be eliminated to address concerns in two specific scenarios:

To accommodate cases where custom plugins need access to a specific route's configuration, such as PHA plugin, the framework will continue to provide an API named getRoutesConfig. This ensures that while direct compilation is removed to streamline processes, essential route configuration information remains accessible as needed.

Additional context | 额外信息

For apps configured as SPA, the pageConfig will not be applied to update the HTML. Developers who need to customize the initial HTML structure can directly modify the document.tsx file to implement the required configurations.