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: 解决 headScripts 链接与 publicPath 不匹配 #11289

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

wsafight
Copy link
Contributor

@wsafight wsafight commented Jul 16, 2024

使用 PUBLIC_PATH 打包好了就会有问题呢,对新同学不太友好。
是否有其他的解法,帮助 scripts/loading.js 添加前缀

Summary by CodeRabbit

  • 新功能
    • 配置了动态公共路径以支持脚本,使不同部署环境的兼容性更强。

Copy link

coderabbitai bot commented Jul 16, 2024

Walkthrough

最近的更改专注于在 config.ts 文件中引入和配置 PUBLIC_PATH 变量,以便在应用程序不在根目录时指定公共路径。该变量用于动态设置 publicPath 属性,并更新脚本源路径,以确保在不同部署环境中的正确性和兼容性。

Changes

文件 更改摘要
config/config.ts 引入了 PUBLIC_PATH 变量,初始化为 '/',并调整了 publicPath 和脚本源路径

Poem

在代码的土地上,路径交织,
publicPath 现在已对齐。
斜杠设置,路径清晰,
兼容性不会消失。
兔子的故事,迅速而明亮,
设置路由,工作正当。 🌟


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>.
    • 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 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.

CodeRabbit Configuration 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 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 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

github-actions bot commented Jul 16, 2024

🎊 PR Preview has been successfully built and deployed to https://ant-design-pro-preview-pr-11289.surge.sh

@liuxuewei
Copy link

liuxuewei commented Jul 16, 2024 via email

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 559c01d and 800a9ea.

Files selected for processing (1)
  • config/config.ts (3 hunks)
Additional comments not posted (2)
config/config.ts (2)

138-138: Correctly updated headScripts path.

The update to the headScripts path to include PUBLIC_PATH ensures consistency with the publicPath. It's important to test that loading.js loads correctly in different environments.

Verification successful

Correctly updated headScripts path.

The update to the headScripts path to include PUBLIC_PATH ensures consistency with the publicPath. It's important to test that loading.js loads correctly in different environments.

  • PUBLIC_PATH is defined and used consistently in config/config.ts.
  • No environment-specific settings for PUBLIC_PATH were found.
  • The reference to loading.js in headScripts should work as expected.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `loading.js` loads correctly with the updated `headScripts` path.

# Test: Check the loading of `loading.js` in different environments.
echo "Test loading of scripts/loading.js in various deployment environments."

Length of output: 150


Script:

#!/bin/bash
# Search for the definition of PUBLIC_PATH in the codebase
rg 'PUBLIC_PATH'

# Search for the usage of headScripts in the codebase
rg 'headScripts'

Length of output: 348


Script:

#!/bin/bash
# Search for environment-specific settings for PUBLIC_PATH
rg 'PUBLIC_PATH' --glob '!config/config.ts'

# Search for references to loading.js in the final output or build files
rg 'loading.js'

Length of output: 177


25-25: Good implementation of dynamic publicPath.

The approach to dynamically set the publicPath based on PUBLIC_PATH and ensure it ends with a slash is effective. However, it's essential to verify that this behaves as expected across all deployment scenarios.

config/config.ts Outdated
* @description 部署时的路径,如果部署在非根目录下,需要配置这个变量
* @doc https://umijs.org/docs/api/config#publicpath
*/
const PUBLIC_PATH: string = '';
Copy link

Choose a reason for hiding this comment

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

Consider documenting the expected handling of PUBLIC_PATH.

The declaration of PUBLIC_PATH as an empty string is clear, but it could benefit from additional comments explaining how it should be set or overridden, especially for new users or different environments.

Would you like me to add more detailed comments or handle this through environment-specific configurations?

config/config.ts Outdated Show resolved Hide resolved
config/config.ts Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 800a9ea and 6c58101.

Files selected for processing (1)
  • config/config.ts (3 hunks)
Additional comments not posted (3)
config/config.ts (3)

10-15: 增强 PUBLIC_PATH 的文档

当前的 JSDoc 注释提供了基本信息,但考虑到新用户或不同环境的需求,建议添加更详细的使用示例或场景描述。


25-25: 条件设置 publicPath 的实现审查

此代码段确保 publicPath 格式正确,对于资源加载非常关键。此实现适当且有效。


137-137: 审查 headScripts 的修改

此修改直接关联到 PR 的目标,即解决 headScripts 链接与 publicPath 不匹配的问题。实现方式正确,符合预期目标。

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c58101 and 68cee36.

Files selected for processing (1)
  • config/config.ts (3 hunks)
Additional comments not posted (2)
config/config.ts (2)

10-16: 文档完善

PUBLIC_PATH 的引入和文档说明非常清晰,有助于理解其用途。建议在文档中添加一些示例值,以展示如何根据不同环境配置此变量。


25-25: 配置使用 PUBLIC_PATH

publicPathheadScripts 中使用 PUBLIC_PATH 是正确的,确保了在非根部署路径下资源能正确加载。建议进行全面测试,验证构建后的完整路径是否符合预期。

运行以下脚本来验证完整路径的构建:

Also applies to: 137-137

Verification successful

确认 PUBLIC_PATH 的使用

config/config.ts 中,PUBLIC_PATH 被正确地用于 publicPath 和脚本路径的构建。这确保了在非根路径部署时资源能够正确加载。建议在部署环境中进行测试,以验证路径构建是否符合预期。

  • config/config.ts: publicPath: PUBLIC_PATH
  • config/config.ts: { src: ${PUBLIC_PATH}scripts/loading.js, async: true }
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证构建后的完整路径是否符合预期。

# 测试:搜索完整路径的使用情况。预期:只有符合新签名的出现。
rg --type typescript -A 5 $'PUBLIC_PATH'

Length of output: 74


Script:

#!/bin/bash
# 描述:验证构建后的完整路径是否符合预期。

# 测试:搜索 `PUBLIC_PATH` 的使用情况。
rg -A 5 'PUBLIC_PATH'

Length of output: 816

config/config.ts Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 68cee36 and 7f25fe5.

Files selected for processing (1)
  • config/config.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • config/config.ts

@afc163 afc163 changed the title #FIX: 解决 headScripts 链接与 publicPath 不匹配 fix: 解决 headScripts 链接与 publicPath 不匹配 Aug 31, 2024
@afc163 afc163 merged commit e48e314 into ant-design:master Aug 31, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants