@tarojs/parse-css-to-stylesheet 0.0.39 → 0.0.41
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 +56 -1
- package/index.d.ts +3 -0
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -181,7 +181,7 @@ const code = parse(jsxCode, [cssCode1, cssCode2, ...], {
|
|
|
181
181
|
| \[attribute=value] | \[target=blank] | 选择所有使用 target="blank"的元素 | ❌ |
|
|
182
182
|
| ... | | 其他 | ❌ |
|
|
183
183
|
|
|
184
|
-
###
|
|
184
|
+
### 伪元素
|
|
185
185
|
|
|
186
186
|
- 支持**before、after**,
|
|
187
187
|
|
|
@@ -196,3 +196,58 @@ const code = parse(jsxCode, [cssCode1, cssCode2, ...], {
|
|
|
196
196
|
| :root | :root | 选择文档的根元素 | ❌ |
|
|
197
197
|
| :checked | input:checked | 选择每个选中的输入元素 | ❌ |
|
|
198
198
|
| ... | | 其他 | ❌ |
|
|
199
|
+
|
|
200
|
+
## 常见问题
|
|
201
|
+
|
|
202
|
+
### 1. 跨组件传递 className、style
|
|
203
|
+
|
|
204
|
+
#### ❌ 错误做法
|
|
205
|
+
|
|
206
|
+
比如业务上针对`@tarojs/components`的组件进行重导出,如引入了`Image`,对其进行了**二次封装**,然后通过一个入口统一导出如:
|
|
207
|
+
|
|
208
|
+
```js
|
|
209
|
+
// ./components.js
|
|
210
|
+
import { View, Text } from "@tarojs/components";
|
|
211
|
+
|
|
212
|
+
// 这里的Image实际上是对TaroImage的二次封装,一样的暴露出style和classname使用
|
|
213
|
+
export { default as Image } from "./xxxx";
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- 在 Taro 编译的视角来看`<Image/>`已经是一个**自定义组件**,并且它接收了`className`,也就说明了它的类名其实是往下传递了,我们会在运行时进行**样式合成**
|
|
217
|
+
- `<View/>`和`<Text/>`其实是原封不动的直接导出的,本质上它并不是一个自定义组件,所以 Taro 在编译时,会在**编译阶段将样式赋予上去**
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
// 注意:这里的组件从统一入口进行导入
|
|
221
|
+
import { View, Image } from "./components";
|
|
222
|
+
|
|
223
|
+
function Index() {
|
|
224
|
+
return (
|
|
225
|
+
<View className="xxx">
|
|
226
|
+
<Image className="xxxxxx" />
|
|
227
|
+
</View>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
但是问题来了,这里在实际使用时,`<View/>`和`<Image/>`都是通过`'./components'`导入,编译阶段无法知道他们是**Taro 组件**还是**自定义组件**,顾在实际运行时,都会视为**自定义组件**对待
|
|
233
|
+
|
|
234
|
+
因为**自定义组件**是在**运行时动态合成样式**,顾性能远不及**Taro 组件**
|
|
235
|
+
|
|
236
|
+
#### ✅ 正确做法
|
|
237
|
+
|
|
238
|
+
如果 Taro 组件没有二次封装,我们建议从`@tarojs/components`导入,提供编译的优化效果
|
|
239
|
+
|
|
240
|
+
```js
|
|
241
|
+
// 自定义组件引入
|
|
242
|
+
import { Image } from "./components";
|
|
243
|
+
// Taro组件引入
|
|
244
|
+
import { View } from "@tarojs/components";
|
|
245
|
+
|
|
246
|
+
function Index() {
|
|
247
|
+
return (
|
|
248
|
+
<View className="xxx">
|
|
249
|
+
<Image className="xxxxxx" />
|
|
250
|
+
</View>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
```
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/parse-css-to-stylesheet",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -55,18 +55,18 @@
|
|
|
55
55
|
"packageManager": "yarn@3.6.4",
|
|
56
56
|
"repository": "https://github.com/NervJS/parse-css-to-stylesheet",
|
|
57
57
|
"optionalDependencies": {
|
|
58
|
-
"@tarojs/parse-css-to-stylesheet-win32-x64-msvc": "0.0.
|
|
59
|
-
"@tarojs/parse-css-to-stylesheet-darwin-x64": "0.0.
|
|
60
|
-
"@tarojs/parse-css-to-stylesheet-linux-x64-gnu": "0.0.
|
|
61
|
-
"@tarojs/parse-css-to-stylesheet-darwin-arm64": "0.0.
|
|
62
|
-
"@tarojs/parse-css-to-stylesheet-android-arm64": "0.0.
|
|
63
|
-
"@tarojs/parse-css-to-stylesheet-linux-arm64-gnu": "0.0.
|
|
64
|
-
"@tarojs/parse-css-to-stylesheet-linux-arm64-musl": "0.0.
|
|
65
|
-
"@tarojs/parse-css-to-stylesheet-win32-arm64-msvc": "0.0.
|
|
66
|
-
"@tarojs/parse-css-to-stylesheet-linux-arm-gnueabihf": "0.0.
|
|
67
|
-
"@tarojs/parse-css-to-stylesheet-linux-x64-musl": "0.0.
|
|
68
|
-
"@tarojs/parse-css-to-stylesheet-win32-ia32-msvc": "0.0.
|
|
69
|
-
"@tarojs/parse-css-to-stylesheet-android-arm-eabi": "0.0.
|
|
70
|
-
"@tarojs/parse-css-to-stylesheet-darwin-universal": "0.0.
|
|
58
|
+
"@tarojs/parse-css-to-stylesheet-win32-x64-msvc": "0.0.41",
|
|
59
|
+
"@tarojs/parse-css-to-stylesheet-darwin-x64": "0.0.41",
|
|
60
|
+
"@tarojs/parse-css-to-stylesheet-linux-x64-gnu": "0.0.41",
|
|
61
|
+
"@tarojs/parse-css-to-stylesheet-darwin-arm64": "0.0.41",
|
|
62
|
+
"@tarojs/parse-css-to-stylesheet-android-arm64": "0.0.41",
|
|
63
|
+
"@tarojs/parse-css-to-stylesheet-linux-arm64-gnu": "0.0.41",
|
|
64
|
+
"@tarojs/parse-css-to-stylesheet-linux-arm64-musl": "0.0.41",
|
|
65
|
+
"@tarojs/parse-css-to-stylesheet-win32-arm64-msvc": "0.0.41",
|
|
66
|
+
"@tarojs/parse-css-to-stylesheet-linux-arm-gnueabihf": "0.0.41",
|
|
67
|
+
"@tarojs/parse-css-to-stylesheet-linux-x64-musl": "0.0.41",
|
|
68
|
+
"@tarojs/parse-css-to-stylesheet-win32-ia32-msvc": "0.0.41",
|
|
69
|
+
"@tarojs/parse-css-to-stylesheet-android-arm-eabi": "0.0.41",
|
|
70
|
+
"@tarojs/parse-css-to-stylesheet-darwin-universal": "0.0.41"
|
|
71
71
|
}
|
|
72
72
|
}
|