Open
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for the “tilde” (~) import syntax in CSS files when using esbuild, ensuring @import "~foo/bar.css" is rewritten to @import "foo/bar.css" during server-side builds.
- Introduce
createCSSImportPluginto handle tilde imports in pure CSS files. - Integrate the new plugin ahead of CSS modules and inline‐style transforms in the esbuild pipeline.
- Update the inline loader and add tests/README/example to cover tilde‐syntax handling.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| esbuildCSSImportPlugin.ts | New esbuild plugin to rewrite @import "~..." lines. |
| applyServerSideProcessor.ts | Splice in the CSS import plugin before other style plugins. |
| tests/cssImportTransform.test.ts | Tests for inline loader’s tilde import support. |
| README.md | Documentation for tilde import transform feature. |
| transform-styles.ts | Global inline loader update for tilde import handling. |
| example/css-import-example.css | Usage example demonstrating tilde imports. |
| .changeset/pink-feet-jog.md | Version bump and summary for CSS build support. |
Comments suppressed due to low confidence (1)
packages/plugin-rax-compat/src/services/styles/tests/cssImportTransform.test.ts:4
- Tests currently only exercise the inline loader. It would be valuable to add unit tests directly for
createCSSImportPluginto verify that pure.cssfiles are correctly rewritten by the plugin.
describe('CSS Import Tilde Transform for ESBuild', () => {
packages/plugin-rax-compat/src/services/styles/applyServerSideProcessor.ts
Outdated
Show resolved
Hide resolved
ClarkXia
previously approved these changes
Jul 16, 2025
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## release/next #7121 +/- ##
===============================================
Coverage ? 78.83%
===============================================
Files ? 223
Lines ? 20117
Branches ? 2535
===============================================
Hits ? 15860
Misses ? 4217
Partials ? 40 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
answershuto
previously approved these changes
Jul 17, 2025
The base branch was changed.
Collaborator
Author
|
https://lesscss.org/features/#import-atrules-feature-import-options 考虑到使用率很低, 暂不在本版本做支持 |
ClarkXia
previously approved these changes
Aug 4, 2025
ClarkXia
approved these changes
Aug 4, 2025
XGHeaven
approved these changes
Aug 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CSS Import Tilde Transform
功能概述
这个功能添加了对 CSS 中
~引入语法的支持,将@import "~@ali/xxx"自动转换为@import "@ali/xxx",以兼容 esbuild 的模块解析。注意: webpack 本身已经支持
~语法,所以客户端构建不需要额外处理。实现方式
1. 服务端渲染(SSR/SSG)- ESBuild 插件
文件:
applyServerSideProcessor.tsESBuildInlineStylePlugin中添加了onResolve钩子~开头的模块路径并解析为正确的 node_modules 路径2. 内联样式处理
文件:
transform-styles.tsstyleSheetLoader函数中直接处理转换转换规则
@import "~@ali/package/style.css"@import "@ali/package/style.css"@import '~@company/design/tokens.css'@import '@company/design/tokens.css'使用场景
第三方包引入
内部包引入
注意事项
~语法,所以只在服务端渲染(使用 esbuild)时需要转换@import语句中的~语法