Skip to content

Comments

chore: 传递postcss-url 的配置#18306

Merged
Single-Dancer merged 1 commit intoNervJS:mainfrom
Yang03:fix-postCss-url
Sep 12, 2025
Merged

chore: 传递postcss-url 的配置#18306
Single-Dancer merged 1 commit intoNervJS:mainfrom
Yang03:fix-postCss-url

Conversation

@Yang03
Copy link
Contributor

@Yang03 Yang03 commented Sep 6, 2025

这个 PR 做了什么? (简要描述所做更改)
修复postcss-url 无法传递参数,出现 postcss-url: Image type is svg and link contains #. Postcss-url cant handle svg fragments. SVG file fully inlined 中warning 时,无法通过postcss url 提供的参数关闭

这个 PR 是什么类型? (至少选择一个)

  • 错误修复 (Bugfix) issue: fix vue3 版本引入本地含svg的iconfont报错 #13008
  • 新功能 (Feature)
  • 代码重构 (Refactor)
  • TypeScript 类型定义修改 (Types)
  • 文档修改 (Docs)
  • 代码风格更新 (Code style update)
  • 构建优化 (Chore)
  • 其他,请描述 (Other, please describe):

这个 PR 涉及以下平台:

  • 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 钉钉小程序
  • QQ 小程序
  • 飞书小程序
  • 快手小程序
  • 头条小程序

Summary by CodeRabbit

  • 改进
    • 现支持在小程序构建中通过 postcssOption.url 覆盖 postcss-url 的配置(如启用开关与资源路径设置),保留合理默认值。
    • 当未提供自定义配置时,保持原有行为与插件顺序不变,确保兼容性与稳定性。

@coderabbitai
Copy link

coderabbitai bot commented Sep 6, 2025

Walkthrough

在 getDefaultPostcssConfig 中,postcss-url 插件的配置由固定 defaultUrlOption 改为与用户提供的 options.url 合并:{ ...defaultUrlOption, ...(options?.url || {}) }。其余插件与顺序保持不变;未改动导出/公开接口。

Changes

Cohort / File(s) Summary
PostCSS 配置合并调整
packages/taro-webpack5-runner/src/postcss/postcss.mini.ts
将 postcss-url 的插件配置由使用固定 defaultUrlOption 改为浅合并 defaultUrlOptionoptions?.url:`{ ...defaultUrlOption, ...(options?.url

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Runner / 调用方
    participant Config as getDefaultPostcssConfig
    participant Url as postcss-url 插件

    Caller->>Config: 请求 PostCSS 配置 (options)
    Config->>Config: 计算 urlOpts = { ...defaultUrlOption, ...(options?.url || {}) }
    Config->>Url: 以 urlOpts 实例化 postcss-url
    Config-->>Caller: 返回包含各插件的数组(顺序未变)

    note right of Config: 若未提供 options.url 则使用默认值
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks (5 passed)

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed PR 标题 “chore: 传递postcss-url 的配置” 简洁明了地反映了此次变更的核心,即允许向 postcss-url 插件传递自定义配置,与实际代码改动高度契合且无冗余描述。
Linked Issues Check ✅ Passed 该 PR 在 getDefaultPostcssConfig 中将 defaultUrlOption 与用户提供的 url 配置合并,解决了原先无法传递 postcss-url 选项的问题,使用户能够通过配置项抑制 SVG 片段警告,完整满足了 issue #13008 的核心需求。
Out of Scope Changes Check ✅ Passed 此次变更仅围绕 postcss-url 插件的配置传递逻辑进行调整,未涉及其他功能模块或与 linked issue 无关的代码改动,变更范围清晰且无越界内容。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

小兔敲键轻声鸣,
默认与配巧相拼。
URL 插件随心定,
队形未改仍整齐。
合并一笔田更宁。 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b61596 and 16b62b1.

📒 Files selected for processing (1)
  • packages/taro-webpack5-runner/src/postcss/postcss.mini.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/taro-webpack5-runner/src/postcss/postcss.mini.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
packages/taro-webpack5-runner/src/postcss/postcss.mini.ts (1)

48-71: 合并 url 配置方向正确,但建议兼容布尔禁用并使用深合并;同时从 options 中剔除 url 以避免无效遍历

  • 兼容写法:若用户将 postcssOption.url 配置为布尔值(例如 false),当前实现会因 options?.url || {} 将其当作 falsy 而忽略,导致无法关闭插件。建议将布尔值映射为 { enable: <bool> }
  • 合并方式:与上面的 autoprefixer/pxtransform/htmltransform 保持一致,使用 recursiveMerge 做深合并,避免未来默认 config 字段被浅合并覆盖。
  • 细节优化:...Object.entries(options) 会带上 url,但在 getPostcssPlugins 中会被过滤(['cssModules','url']),徒增一次遍历。建议构造 restOptions 剔除后再展开。

可参考如下 diff:

-  const { autoprefixer, pxtransform, htmltransform, ...options } = postcssOption
+  const { autoprefixer, pxtransform, htmltransform, url: urlOpt, ...restOptions } = postcssOption
@@
-  return [
+  // 与其他插件保持一致,深合并并兼容布尔禁用
+  const urlOption = recursiveMerge(
+    {},
+    defaultUrlOption,
+    typeof urlOpt === 'boolean' ? { enable: urlOpt } : (urlOpt || {})
+  )
+
+  return [
@@
-    ['postcss-url', { ...defaultUrlOption, ...(options?.url || {}) }, require('postcss-url')],
+    ['postcss-url', urlOption, require('postcss-url')],
@@
-    ...Object.entries(options)
+    ...Object.entries(restOptions)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1676906 and 7b61596.

📒 Files selected for processing (1)
  • packages/taro-webpack5-runner/src/postcss/postcss.mini.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc

@codecov
Copy link

codecov bot commented Sep 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.05%. Comparing base (54c1c98) to head (16b62b1).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #18306      +/-   ##
==========================================
- Coverage   55.06%   55.05%   -0.01%     
==========================================
  Files         416      416              
  Lines       21564    21560       -4     
  Branches     5282     5242      -40     
==========================================
- Hits        11874    11870       -4     
- Misses       8032     8034       +2     
+ Partials     1658     1656       -2     
Flag Coverage Δ
taro-cli 72.85% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 53.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Single-Dancer Single-Dancer added this to the 4.1.7 milestone Sep 10, 2025
@Single-Dancer Single-Dancer merged commit 8432bc9 into NervJS:main Sep 12, 2025
24 checks passed
This was referenced Sep 13, 2025
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.

vue3 版本引入本地含svg的iconfont报错

2 participants