-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
📝 WalkthroughWalkthrough此次更改主要涉及 Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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: './'
是一个完整的解决方案。这个改动:
- 保持了所有构建配置的一致性
- 解决了静态资源路径的问题
- 适用于不同的部署场景
建议在发布前进行完整的构建测试,确保所有资源都能正确加载。
考虑在项目的构建文档中添加关于
publicPath
配置的说明,以及不同部署场景下的最佳实践。
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
📒 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'
),建议确认以下几点:
- 在不同的部署环境中验证资源加载
- 确保压缩版本(.min.js)中的资源路径也正确解析
运行以下脚本来验证压缩版本中的资源路径:
✅ Verification successful
publicPath 配置验证完成,无需额外关注
根据代码分析结果,当前的 publicPath: './'
配置是合理的:
- 该配置在多个构建配置中一致使用,包括集成测试配置
libraryTarget: 'global'
的设置仅影响模块导出方式,与资源路径解析无关- 相对路径
'./'
是标准做法,确保了资源在不同环境下都能正确加载
🏁 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
Types
Background or solution
ChangeLog
fix: static files should be requested using relative paths
Summary by CodeRabbit