umijs / umi

A framework in react community ✨
https://umijs.org
MIT License
15.05k stars 2.64k forks source link

feat: 支持htmlSuffix、dynamicRoot #12496

Open flgame opened 1 week ago

flgame commented 1 week ago

公司好几个项目升级umi4.x需要用到,希望能支持 https://github.com/umijs/umi/issues/12301

  1. htmlSuffix: 会生成 xxx.html静态文件及路由,非xxx/index.html
  2. dynamicRoot: 可不用做任何修改部署在任意目录下

有一点需要说明的是
dynamicRoot 为新增配置,原publicPath: './'相对路径的方式也是有问题的,使用当前规则没问题。
对于dynamicRoot:true, htmlSuffix: false的场景,由于/page1 和 /page1/index.html 得到的相对路径不一样,但是又是同一个文件,对于headScripts等脚本路径是编译时确定的,没办法对前面两个路由同时生效。

已添加examples/export-static项目,且测试以下场景都正常:
① 约定式路由,不开启 dynamicRoot 、不开启 htmlSuffix 。 ② 约定式路由,开启 dynamicRoot 、不开启 htmlSuffix 。 ③ 约定式路由,不开启 dynamicRoot 、开启 htmlSuffix 。 ④ 约定式路由,开启 dynamicRoot 、开启 htmlSuffix 。 ⑤ 配置式路由,不开启 dynamicRoot 、不开启 htmlSuffix 。 ⑥ 配置式路由,开启 dynamicRoot 、不开启 htmlSuffix 。 ⑦ 配置式路由,不开启 dynamicRoot 、开启 htmlSuffix 。 ⑧ 配置式路由,开启 dynamicRoot 、开启 htmlSuffix 。

使用Whistle测试,对应htmlSuffix: true配置:

^export-static.local/x/y/page1$ file:///home/user1/projects/umi/examples/export-static/dist/page1.html resCors://enable
^export-static.local/x/y/page1/page1_1$ file:///home/user1/projects/umi/examples/export-static/dist/page1/page1_1.html resCors://enable
export-static.local/x/y file:///home/user1/projects/umi/examples/export-static/dist resCors://enable

^export-static.local/page1$ file:///home/user1/projects/umi/examples/export-static/dist/page1.html resCors://enable
^export-static.local/page1/page1_1$ file:///home/user1/projects/umi/examples/export-static/dist/page1/page1_1.html resCors://enable
export-static.local file:///home/user1/projects/umi/examples/export-static/dist resCors://enable

htmlSuffix: false配置:

^export-static.local/x/y/page1/$ file:///home/user1/projects/umi/examples/export-static/dist/page1/index.html resCors://enable
^export-static.local/x/y/page1/page1_1$ file:///home/user1/projects/umi/examples/export-static/dist/page1/page1_1/index.html resCors://enable
export-static.local/x/y file:///home/user1/projects/umi/examples/export-static/dist resCors://enable

^export-static.local/page1/$ file:///home/user1/projects/umi/examples/export-static/dist/page1/index.html resCors://enable
^export-static.local/page1/page1_1$ file:///home/user1/projects/umi/examples/export-static/dist/page1/page1_1/index.html resCors://enable
export-static.local file:///home/user1/projects/umi/examples/export-static/dist resCors://enable

之前的PR已关闭,感谢 @fz6m 的修改意见,详见:https://github.com/umijs/umi/pull/12400

Summary by CodeRabbit

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **umi** | ⬜️ Ignored ([Inspect](https://vercel.com/chenchengs-projects-4255bdcd/umi/CSir77tqDqRqKZUaZ5LGTBxnCrZc)) | [Visit Preview](https://umi-git-fork-flgame-feature-dc20d6-chenchengs-projects-4255bdcd.vercel.app) | | Jun 27, 2024 9:30am |
coderabbitai[bot] commented 1 week ago

[!WARNING]

Rate limit exceeded

@flgame has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 41 seconds before requesting another review.

How to resolve this issue? After the wait time has elapsed, a review can be triggered using the `@coderabbitai review` command as a PR comment. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit.
How do rate limits work? CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our [FAQ](https://coderabbit.ai/docs/faq) for further information.
Commits Files that changed from the base of the PR and between 00f90746e2309ea6f33a5c8bd8aff12f4cbee84a and 44fbe0b94fd988040237b73ee3618e3d65332109.

Walkthrough

此次变更引入了针对静态文件导出的配置,包括HTML后缀、动态根路径和散列处理的设置。新增和修改的文件涵盖了页面组件、样式文件及核心控制逻辑,优化了静态导出功能的处理流程。

Changes

文件路径 变更摘要
examples/export-static/.umirc.ts 新增导出静态文件的配置,包含HTML后缀、动态根路径及散列的设定。
examples/export-static/package.json 新增了项目构建、开发、初始化和启动的脚本配置,及Umi相关依赖。
examples/export-static/src/pages/404.tsx
examples/export-static/src/pages/page1/index.tsx
examples/export-static/src/pages/page1/page1_1/index.tsx
添加了新的React功能组件用于显示页面内容,例如404页面和其他具体页面。
examples/export-static/src/pages/bar.css
examples/export-static/src/pages/foo.less
新增CSS和Less样式文件,定义了页面元素的样式规则。
examples/export-static/src/pages/index.tsx 增加了主页的React功能组件,使用Helmet进行文档头管理,并包含多个设置了CSS模块的链接。
packages/preset-umi/src/features/exportStatic/exportStatic.ts 进行了核心逻辑和控制流程的修改,引入了多个函数例如isHtmlRoutegetHtmlPath,并增加了对公共路径和资源的处理。

Poem

代码兔子跳跃欢,
配置静态焕新颜。
页面样式齐亮相,
功能优化稳如山。
新增函数巧妙设,
项目开发事半功倍。
静态导出更高效,
编码之路共美妙。


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.