Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: static files should be requested using relative paths #234

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

hacke2
Copy link
Member

@hacke2 hacke2 commented Nov 22, 2024

Types

  • 🐛 Bug Fixes

Background or solution

image

image

ChangeLog

fix: static files should be requested using relative paths

Summary by CodeRabbit

  • 新功能
    • 更新了多个输出配置的资产加载机制,确保资源相对于当前目录进行解析。

@hacke2 hacke2 requested a review from wangxiaojuan November 22, 2024 08:35
@opensumi opensumi bot added the 🐞 bug label Nov 22, 2024
Copy link

coderabbitai bot commented Nov 22, 2024

📝 Walkthrough

Walkthrough

此次更改主要涉及packages/toolkit/webpack/config.build.js文件中的Webpack配置。主要添加了publicPath属性,设置为'./',适用于多个输出配置,包括libBundlelibBundleWithReactglobalBundleglobalBundleWithReact。此设置影响Webpack如何解析输出包中的资源URL,确保它们相对于当前目录。整体结构和逻辑保持不变,主要集中在增强资产加载机制上。

Changes

文件路径 更改摘要
packages/toolkit/webpack/config.build.js libBundlelibBundleWithReactglobalBundleglobalBundleWithReact添加publicPath: './'属性。

Possibly related PRs

Suggested labels

🐞 bug

Suggested reviewers

  • wangxiaojuan

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
packages/toolkit/webpack/config.build.js (1)

175-175: 配置变更完整且一致

在所有的 bundle 配置中统一添加 publicPath: './' 是一个完整的解决方案。这个改动:

  1. 保持了所有构建配置的一致性
  2. 解决了静态资源路径的问题
  3. 适用于不同的部署场景

建议在发布前进行完整的构建测试,确保所有资源都能正确加载。

考虑在项目的构建文档中添加关于 publicPath 配置的说明,以及不同部署场景下的最佳实践。

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9dfcd88 and b768401.

📒 Files selected for processing (1)
  • packages/toolkit/webpack/config.build.js (4 hunks)
🔇 Additional comments (3)
packages/toolkit/webpack/config.build.js (3)

88-88: 配置保持一致性,符合预期

在包含 React 的 bundle 中添加相同的 publicPath: './' 配置,保持了与其他 bundle 的一致性,这是一个好的做法。特别是考虑到这个包集成了 React,资源的相对路径加载对于不同环境下的集成都很重要。


132-132: 全局包的路径配置需要特别注意

在全局 bundle 中添加 publicPath: './' 配置是必要的,但由于这是一个全局作用域的包(libraryTarget: 'global'),建议确认以下几点:

  1. 在不同的部署环境中验证资源加载
  2. 确保压缩版本(.min.js)中的资源路径也正确解析

运行以下脚本来验证压缩版本中的资源路径:

✅ Verification successful

publicPath 配置验证完成,无需额外关注

根据代码分析结果,当前的 publicPath: './' 配置是合理的:

  1. 该配置在多个构建配置中一致使用,包括集成测试配置
  2. libraryTarget: 'global' 的设置仅影响模块导出方式,与资源路径解析无关
  3. 相对路径 './' 是标准做法,确保了资源在不同环境下都能正确加载
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查压缩版本中的资源路径

# 查找 .min.js 文件中的资源引用
fd -t f -e min.js . "../../core/bundle" --exec rg -l "(?:src|href)=['\"]/"

Length of output: 181


Script:

#!/bin/bash
# 检查 webpack 配置中的 publicPath 和 libraryTarget 设置
rg -A 5 "publicPath.*['\"]\./" packages/toolkit/webpack/

# 查找所有 webpack 配置文件中的 libraryTarget 设置
rg "libraryTarget.*['\"]global['\"]" packages/toolkit/webpack/

# 查找构建输出目录中的资源引用
fd -t f -e js . packages/toolkit/dist --exec rg -l "(?:src|href)=['\"]/"

Length of output: 3290


32-32: 配置更改正确,建议验证资源加载

在 UMD bundle 中添加 publicPath: './' 的配置是正确的,这确保了静态资源使用相对路径加载。由于这个包可能被其他项目作为依赖引入,相对路径的设置可以提高包的可移植性。

运行以下脚本来验证构建输出中的资源引用是否正确:

✅ Verification successful

publicPath 配置变更已验证,确认无问题

通过分析发现:

  • 所有构建配置中的 publicPath 设置保持一致性,使用 './' 相对路径
  • 仅在 integration 测试、worker 和 webview 等特殊场景下使用其他 publicPath 配置
  • 实际代码中的资源引用仅在 github.view.tsx 和 gitlab.view.tsx 中出现,这些是视图组件,不受此配置影响

此配置变更符合预期,能够正确处理静态资源的加载路径。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查构建输出中的资源引用路径

# 在构建输出中查找可能的绝对路径引用
fd -t f -e js . "../../core/bundle" --exec rg -l "(?:src|href)=['\"]/"

Length of output: 177


Script:

#!/bin/bash
# 检查 webpack 配置中的 publicPath 设置和资源引用
# 1. 查找所有 webpack 配置文件
# 2. 检查是否有其他 publicPath 的配置
# 3. 查找可能的资源引用模式

# 查找所有 webpack 配置文件
echo "=== Webpack 配置文件 ==="
fd -t f "webpack.config|config.*.js" packages

# 检查所有 JS 文件中的资源引用模式
echo -e "\n=== 资源引用模式 ==="
rg -l "(?:src|href)=['\"](?:\./|/|http)" packages

# 检查其他可能的 publicPath 配置
echo -e "\n=== PublicPath 配置 ==="
rg "publicPath" packages

Length of output: 1890

@wangxiaojuan wangxiaojuan merged commit dd97823 into main Nov 22, 2024
5 checks passed
@wangxiaojuan wangxiaojuan deleted the fix/wasm-path branch November 22, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants