@weapp-tailwindcss/lynx 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -8
- package/README.zh-CN.md +114 -0
- package/dist/index.cjs +11 -1
- package/dist/index.js +11 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# @weapp-tailwindcss/lynx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> English | [简体中文](./README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Tailwind CSS 4 integration for ReactLynx and Rspeedy. It invokes `weapp-tailwindcss` through Rspeedy's Rspack lifecycle to produce standard CSS for Lynx, preserves native ReactLynx `className`, and introduces no runtime stylesheet or JSX transform.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
pnpm add @weapp-tailwindcss/lynx tailwindcss
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Configure
|
|
12
14
|
|
|
13
15
|
```ts
|
|
14
|
-
// lynx.config.ts
|
|
15
16
|
import { defineConfig } from '@lynx-js/rspeedy'
|
|
16
17
|
import { pluginLynxTailwindcss } from '@weapp-tailwindcss/lynx'
|
|
17
18
|
|
|
@@ -20,11 +21,50 @@ export default defineConfig({
|
|
|
20
21
|
})
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
Import Tailwind CSS 4 from the application CSS entry and point `@source` at the actual source files. Lynx does not need browser preflight, so importing only theme and utilities avoids most compatibility warnings:
|
|
24
25
|
|
|
25
26
|
```css
|
|
26
|
-
@
|
|
27
|
-
|
|
27
|
+
@layer theme, base, components, utilities;
|
|
28
|
+
|
|
29
|
+
@import "tailwindcss/theme.css" layer(theme);
|
|
30
|
+
@import "tailwindcss/utilities.css" layer(utilities) source(none);
|
|
31
|
+
|
|
32
|
+
@source "./**/*.{ts,tsx}";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`pluginLynxTailwindcss` fixes `platform` to `'lynx'`, sets `generator.target` to `'web'`, and enables Lynx-compatible output. Tailwind CSS 4 theme variables are resolved at build time, while application-defined dynamic variables remain unchanged.
|
|
36
|
+
|
|
37
|
+
The current integration supports ReactLynx + Rspeedy and Tailwind CSS 4. It does not cover Rspeedy Web output, non-React Lynx frameworks, or React Native-style runtime style mapping.
|
|
38
|
+
|
|
39
|
+
## Arbitrary values
|
|
40
|
+
|
|
41
|
+
Lynx keeps the original `className`; class names are not escaped as they are for mini app targets. Arbitrary values must appear as complete static strings in files covered by `@source`:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
<view className="h-[45rpx] w-[123px] rounded-[18px] bg-[#123456] p-[13px]" />
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Do not construct arbitrary values at runtime. Enumerate complete class names or register candidates explicitly:
|
|
48
|
+
|
|
49
|
+
```css
|
|
50
|
+
@source inline("w-[120px] w-[240px] bg-[#123456]");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Tailwind generating CSS does not guarantee support from Lynx's native CSS parser. The current encoder removes unsupported properties such as `padding-inline` and `mask-type`, as well as complex selectors containing `:is()` or `:where()`. Use physical-direction utilities such as `pl-*` and `pr-*` when needed, and validate pseudo-elements, interaction states, media queries, and visual effects on the target runtime.
|
|
54
|
+
|
|
55
|
+
Using the full `@import "tailwindcss"` also includes browser preflight. Prefer the theme and utilities entry above when Rspeedy reports unsupported browser selectors.
|
|
56
|
+
|
|
57
|
+
## Validate
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpm --filter @weapp-tailwindcss/lynx test
|
|
61
|
+
pnpm e2e:lynx
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For repository-level visual validation with iOS Simulator and LynxExplorer:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pnpm e2e:lynx:ios
|
|
28
68
|
```
|
|
29
69
|
|
|
30
|
-
|
|
70
|
+
The visual command starts Rspeedy, resolves the actual bundle URL, captures a screenshot, and checks generated colors. The current LynxExplorer iOS build requires manually pasting the URL and selecting Go when prompted.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# @weapp-tailwindcss/lynx
|
|
2
|
+
|
|
3
|
+
> [English](./README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
ReactLynx + Rspeedy 的 Tailwind CSS v4 集成。它通过 Rspeedy 的 Rspack 生命周期调用 `weapp-tailwindcss` 生成 Lynx 可消费的普通 CSS,保留 ReactLynx 原生 `className`,不引入运行时样式表或 JSX 转换。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @weapp-tailwindcss/lynx tailwindcss
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 配置
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// lynx.config.ts
|
|
17
|
+
import { defineConfig } from '@lynx-js/rspeedy'
|
|
18
|
+
import { pluginLynxTailwindcss } from '@weapp-tailwindcss/lynx'
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
plugins: [pluginLynxTailwindcss()],
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
在应用 CSS 入口中引入 Tailwind v4,并用 `@source` 指向实际源码。Lynx 不需要浏览器 preflight,推荐只引入 theme 与 utilities,避免 Rspeedy 输出大量浏览器选择器兼容警告。以下示例假设 CSS 入口是 `src/global.css`,`@source` 路径相对该文件解析:
|
|
26
|
+
|
|
27
|
+
```css
|
|
28
|
+
@layer theme, base, components, utilities;
|
|
29
|
+
|
|
30
|
+
@import "tailwindcss/theme.css" layer(theme);
|
|
31
|
+
@import "tailwindcss/utilities.css" layer(utilities) source(none);
|
|
32
|
+
|
|
33
|
+
@source "./**/*.{ts,tsx}";
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`pluginLynxTailwindcss` 固定使用 `platform: 'lynx'`、`generator.target: 'web'` 与 Lynx 原生兼容输出。Tailwind v4 theme 变量会在构建期静态化,确保 `bg-sky-500`、`p-6`、`text-lg` 等标准 utility 能进入 Lynx 原生样式表;应用自行定义的动态 CSS 变量保持不变。
|
|
37
|
+
|
|
38
|
+
当前集成支持 ReactLynx + Rspeedy 与 Tailwind CSS v4;不覆盖 Rspeedy Web 输出、非 React Lynx 框架或 React Native 风格的运行时样式映射。
|
|
39
|
+
|
|
40
|
+
## 任意值
|
|
41
|
+
|
|
42
|
+
Lynx 集成保留 ReactLynx 原生 `className`,不会像小程序目标一样转义类名。Tailwind CSS v4 可以正常扫描并生成任意值,但最终是否生效还取决于 Lynx 原生 CSS parser 是否支持对应的属性和选择器。
|
|
43
|
+
|
|
44
|
+
任意值必须以完整静态字符串出现在 `@source` 覆盖的文件中:
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
<view className="w-[123px] h-[45rpx] rounded-[18px] bg-[#123456] p-[13px]" />
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
不要在运行时拼接任意值:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
// Tailwind 无法在构建期枚举最终类名。
|
|
54
|
+
<view className={`w-[${width}px]`} />
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
动态场景应枚举完整类名,或使用 `@source inline(...)` 显式注册候选:
|
|
58
|
+
|
|
59
|
+
```css
|
|
60
|
+
@source inline("w-[120px] w-[240px] bg-[#123456]");
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 兼容性矩阵
|
|
64
|
+
|
|
65
|
+
| 类型 | 示例 | 当前状态 |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| 长度与单位 | `w-[123px]`、`h-[45rpx]`、`p-[13px]` | 已验证生成并进入 Lynx bundle |
|
|
68
|
+
| 计算值 | `min-w-[calc(100%-2rem)]` | 已验证 |
|
|
69
|
+
| 颜色 | `bg-[#123456]`、`bg-[rgb(12,34,56)]`、`text-[color:#c31d6b]` | 已验证 |
|
|
70
|
+
| 渐变 | `bg-[radial-gradient(circle_at_20%_20%,#fff,#000)]` | 已验证生成;复杂效果仍建议做真机视觉验收 |
|
|
71
|
+
| 明确类型 | `text-[length:23px]`、`text-[color:#c31d6b]` | 已验证,二义性值推荐显式写 `length:` / `color:` |
|
|
72
|
+
| CSS 变量 | `[--panel-height:240px]`、`max-h-[var(--panel-height)]`、`bg-(--brand-color)` | 已验证;应用自定义变量不会被静态化 |
|
|
73
|
+
| 重要值 | `!bg-[gray]` | Tailwind 可生成,需结合 Lynx 目标版本验收优先级行为 |
|
|
74
|
+
| 布局值 | `aspect-[4/3]`、`grid-cols-[200px_minmax(0,1fr)_80px]` | 已验证生成并进入 bundle |
|
|
75
|
+
| 逻辑属性 | `px-[7.5px]` | 不推荐;Tailwind 生成 `padding-inline`,当前 Lynx encoder 会删除该属性 |
|
|
76
|
+
| 任意 CSS 属性 | `[mask-type:luminance]` | 不支持;当前 Lynx encoder 会删除 `mask-type` |
|
|
77
|
+
| 复杂变体 | `group-[.is-active]:block` | 不支持;生成的 `:is()` / `:where()` 选择器会被 Lynx encoder 删除 |
|
|
78
|
+
| 属性/伪元素/媒体变体 | `data-[state=open]:*`、`before:*`、`hover:*`、`dark:*`、`supports-*` | Tailwind 可生成 CSS,但运行时行为由 Lynx 决定,必须做目标端验收 |
|
|
79
|
+
|
|
80
|
+
`px-[7.5px]` 需要兼容当前 Lynx 时,改用物理方向属性:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
<view className="pl-[7.5px] pr-[7.5px]" />
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 构建警告
|
|
87
|
+
|
|
88
|
+
使用完整的 `@import "tailwindcss"` 会包含浏览器 preflight。Rspeedy 可能报告并移除 `:root`、`:host`、`:where(...)`、`::file-selector-button` 等 Lynx 不支持的浏览器选择器,以及 `padding-inline`、`mask-type`、`text-decoration-line` 等不支持的属性。
|
|
89
|
+
|
|
90
|
+
这些警告需要分两类处理:
|
|
91
|
+
|
|
92
|
+
- preflight 的浏览器专用规则:改用上面的 theme + utilities 入口即可减少噪声。
|
|
93
|
+
- 业务 utility 对应的 selector/property:表示该样式不会进入 Lynx 原生样式表,应调整 Tailwind 写法,不能只忽略警告。
|
|
94
|
+
|
|
95
|
+
## 验证
|
|
96
|
+
|
|
97
|
+
仓库中的任意值单测与真实 Rspeedy bundle 回归可以通过以下命令运行:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pnpm --filter @weapp-tailwindcss/lynx test
|
|
101
|
+
pnpm e2e:lynx
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
测试覆盖长度、`rpx`、`calc()`、颜色、渐变、CSS 变量、重要值、任意属性及常见变体。静态 E2E 只证明 CSS 已生成并进入 bundle;伪元素、交互状态、媒体查询和复杂视觉效果仍应在实际 Lynx 目标端验收。
|
|
105
|
+
|
|
106
|
+
## iOS 视觉验收
|
|
107
|
+
|
|
108
|
+
仓库开发者可在已安装 LynxExplorer 的 iOS Simulator 中运行:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pnpm e2e:lynx:ios
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
命令会启动 Rspeedy、解析实际 bundle URL、将 URL 写入 Simulator pasteboard,并在截图后按生成的 `bg-sky-500` 颜色做像素断言。当前 LynxExplorer iOS 版本没有可用的 deep-link 回调,因此需在提示出现后手动将 URL 粘贴到首页、点击 Go,再回到终端按 Enter;其余截图、裁剪、像素分析和 dev server 清理均自动完成。
|
package/dist/index.cjs
CHANGED
|
@@ -4,15 +4,25 @@ let weapp_tailwindcss_rspack = require("weapp-tailwindcss/rspack");
|
|
|
4
4
|
const PLUGIN_NAME = "weapp-tailwindcss:lynx";
|
|
5
5
|
function normalizeOptions(options) {
|
|
6
6
|
const { rspack: _rspack, generator, ...rest } = options;
|
|
7
|
+
const generatorOptions = generator === false ? {} : generator;
|
|
7
8
|
return {
|
|
8
9
|
...rest,
|
|
10
|
+
rewriteCssImports: true,
|
|
9
11
|
platform: "lynx",
|
|
10
12
|
cssOptions: {
|
|
11
13
|
...options.cssOptions,
|
|
12
14
|
platform: "lynx"
|
|
13
15
|
},
|
|
14
16
|
generator: {
|
|
15
|
-
...
|
|
17
|
+
...generatorOptions,
|
|
18
|
+
webCompat: true,
|
|
19
|
+
styleOptions: {
|
|
20
|
+
...generatorOptions?.styleOptions,
|
|
21
|
+
cssOptions: {
|
|
22
|
+
...generatorOptions?.styleOptions?.cssOptions,
|
|
23
|
+
platform: "lynx"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
16
26
|
target: "web"
|
|
17
27
|
}
|
|
18
28
|
};
|
package/dist/index.js
CHANGED
|
@@ -3,15 +3,25 @@ import { WeappTailwindcss, patchRspackConfig } from "weapp-tailwindcss/rspack";
|
|
|
3
3
|
const PLUGIN_NAME = "weapp-tailwindcss:lynx";
|
|
4
4
|
function normalizeOptions(options) {
|
|
5
5
|
const { rspack: _rspack, generator, ...rest } = options;
|
|
6
|
+
const generatorOptions = generator === false ? {} : generator;
|
|
6
7
|
return {
|
|
7
8
|
...rest,
|
|
9
|
+
rewriteCssImports: true,
|
|
8
10
|
platform: "lynx",
|
|
9
11
|
cssOptions: {
|
|
10
12
|
...options.cssOptions,
|
|
11
13
|
platform: "lynx"
|
|
12
14
|
},
|
|
13
15
|
generator: {
|
|
14
|
-
...
|
|
16
|
+
...generatorOptions,
|
|
17
|
+
webCompat: true,
|
|
18
|
+
styleOptions: {
|
|
19
|
+
...generatorOptions?.styleOptions,
|
|
20
|
+
cssOptions: {
|
|
21
|
+
...generatorOptions?.styleOptions?.cssOptions,
|
|
22
|
+
platform: "lynx"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
15
25
|
target: "web"
|
|
16
26
|
}
|
|
17
27
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/lynx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1
|
|
5
|
-
"description": "Tailwind CSS
|
|
4
|
+
"version": "0.2.1",
|
|
5
|
+
"description": "Tailwind CSS integration for ReactLynx and Rspeedy cross-platform builds. 面向 ReactLynx 与 Rspeedy 跨端构建的 Tailwind CSS 集成。",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"weapp-tailwindcss": "^5.
|
|
46
|
+
"weapp-tailwindcss": "^5.3.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@lynx-js/rspeedy": "^0.16.3",
|