Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,12 @@ function getPathFromScript(
: chunkScript.getAttribute('src')!
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''))
const runtimeBasePath = getRuntimeChunkBasePath()
const path = src.startsWith(runtimeBasePath)
let path = src.startsWith(runtimeBasePath)
? src.slice(runtimeBasePath.length)
: src
if (path.startsWith('/')) {
path = path.slice(1)
}
Comment on lines +380 to +385

Choose a reason for hiding this comment

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

medium

这部分逻辑可以通过方法链和正则表达式来简化,使其成为一个单行表达式。这样不仅代码更简洁,而且可以使用 const 代替 let,增强代码的不可变性,这通常是推荐的最佳实践。

  const path = (src.startsWith(runtimeBasePath) ? src.slice(runtimeBasePath.length) : src).replace(/^\//, '');

return path as ChunkPath | ChunkListPath
}

Expand Down
Loading