-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Rax Compat CSS Import Tilde Transform #7121
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
base: master
Are you sure you want to change the base?
Conversation
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.
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
createCSSImportPlugin
to 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
createCSSImportPlugin
to verify that pure.css
files 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
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:
|
The base branch was changed.
https://lesscss.org/features/#import-atrules-feature-import-options 考虑到使用率很低, 暂不在本版本做支持 |
CSS Import Tilde Transform
功能概述
这个功能添加了对 CSS 中
~
引入语法的支持,将@import "~@ali/xxx"
自动转换为@import "@ali/xxx"
,以兼容 esbuild 的模块解析。注意: webpack 本身已经支持
~
语法,所以客户端构建不需要额外处理。实现方式
1. 服务端渲染(SSR/SSG)- ESBuild 插件
文件:
applyServerSideProcessor.ts
ESBuildInlineStylePlugin
中添加了onResolve
钩子~
开头的模块路径并解析为正确的 node_modules 路径2. 内联样式处理
文件:
transform-styles.ts
styleSheetLoader
函数中直接处理转换转换规则
@import "~@ali/package/style.css"
@import "@ali/package/style.css"
@import '~@company/design/tokens.css'
@import '@company/design/tokens.css'
使用场景
第三方包引入
内部包引入
注意事项
~
语法,所以只在服务端渲染(使用 esbuild)时需要转换@import
语句中的~
语法