Skip to content

Commit 30e1d9c

Browse files
authored
docs: update README.md (#8)
1 parent 21b7dfb commit 30e1d9c

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

README.md

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ English | [中文](https://github.com/baiwusanyu-c/unplugin-vue-cssvars/blob/mas
1515
```mermaid
1616
graph LR
1717
A[vite] -- plugin --> B((unplugin-vue-cssvars))
18-
B -- 1.预处理项目中css文件 --> C(生成CSS Module Map获得包含 v-bind 的 css 代码等信息)
18+
B -- 1.Preprocess css files in the project --> C(Generate CSS Module Map to obtain information such as css code including v-bind)
1919
C --> D
20-
B -- 2.基于步骤1与vue编译器 --> D(根据 SFC 组件信息获得其引用的 CSS Module)
20+
B -- 2.Based on step 1 with vue compiler --> D(Obtain the referenced CSS Module according to the SFC component information)
2121
D --> E
22-
B -- 3.基于vue编译器 --> E(提取 SFC 组件变量)
22+
B -- 3.Based on vue compiler --> E(Extract SFC component tags)
2323
E --> F
24-
B -- 4.注入提升代码 --> F(匹配CSS Module SFC 变量注入代码)
24+
B -- 4.inject code --> F(Match CSS Module and SFC variable injection code)
2525
F --> G((vitejs/plugin-vue))
2626
```
2727

@@ -122,31 +122,31 @@ build({
122122

123123
```typescript
124124
export interface Options {
125-
/**
126-
* 需要转换的路径,默认是项目根目录
127-
* @default process.cwd()
128-
*/
129-
rootDir?: string
130-
/**
131-
* 需要转换的文件名后缀列表(目前只支持.vue)RegExp or glob
132-
*/
133-
include?: FilterPattern
125+
/**
126+
* Provide path which will be transformed
127+
*
128+
* @default process.cwd()
129+
*/
130+
rootDir?: string
131+
/**
132+
* RegExp or glob to match files to be transformed
133+
*/
134+
include?: FilterPattern
134135

135-
/**
136-
* 不需要转换的文件名后缀列表(目前只支持.vue)RegExp or glob
137-
*/
138-
exclude?: FilterPattern
136+
/**
137+
* RegExp or glob to match files to NOT be transformed
138+
*/
139+
exclude?: FilterPattern
139140

140-
/**
141-
* `unplugin-vue-cssvars` 只是做了样式提升注入,其编译依旧依赖于 `@vue/compiler-dom`
142-
* 在某些时候可能会生成重复的 `css` 代码(一般不会,因为打包时会将重复代码删除),例如 `vite` 中关闭构建
143-
* 时压缩选项,`revoke` 则可以在打包时将注入的代码删除
144-
*/
145-
revoke?: boolean
141+
/**
142+
* unplugin-vue-cssvars depends on the vue compiler,
143+
* there may be duplicate css after packaging, here we clear it
144+
*/
145+
revoke?: boolean
146146
}
147147
```
148-
### 关于 revoke 详细说明
149-
有如下两个文件 `App.vue` `test.css`
148+
### Details about revoke
149+
Suppose there are two files `App.vue` and `test.css`
150150
````
151151
<script setup lang="ts">
152152
const color = 'red'
@@ -169,15 +169,15 @@ div {
169169
color: v-bind(color);
170170
}
171171
````
172-
当未使用 `unplugin-vue-cssvars` 使用 `vite` 构建后
172+
After building with `vite` when `unplugin-vue-cssvars` is not used
173173
````
174174
/** test.css **/
175175
div[data-v-2e7c9788] {
176176
color: var(--8bcabd20);
177177
}
178178
````
179-
其中 `color: var(--8bcabd20);` 的哈希并不会出现在组件打包产物中,因为 `vue` 不支持在文件中使用 `v-bind`
180-
当使用 `unplugin-vue-cssvars` 使用 `vite` 构建后(`minify: false`
179+
Among them, the hash of `color: var(--8bcabd20);` will not appear in the component packaging product, because `vue` does not support the use of `v-bind` in the file.
180+
When built with `vite` using `unplugin-vue-cssvars` (`minify: false`)
181181
````
182182
/** test.css **/
183183
div[data-v-1dfefb04] {
@@ -189,8 +189,9 @@ div[data-v-1dfefb04] {
189189
div[data-v-1dfefb04]{color:var(--516b0d4a)}
190190
/* <inject end> */
191191
````
192-
可以看到通过 `unplugin-vue-cssvars` 会生成注入代码,并且依赖于 `@vue/compiler-dom`,其哈希值能够出现在组件打包产物中。
193-
但是观察发现,这段代码是重复的。因此,开启 `revoke` 选项,将移除重复代码
192+
It can be seen that the code will be injected through `unplugin-vue-cssvars`, and it depends on `@vue/compiler-dom`, whose hash value can appear in the component packaging product.
193+
But observation found that this code is repetitive.
194+
Therefore, turning on the `revoke` option will remove duplicate code
194195
````
195196
/** test.css **/
196197
div[data-v-1dfefb04] {
@@ -200,20 +201,21 @@ div[data-v-1dfefb04] {
200201

201202
## Tips
202203

203-
### ● 转换分析时的约定规则
204-
1. `sfc` 中,如果 `@import` 指定了后缀,则根据后缀的文件进行转换分析,否则根据当前 `script` 标签的 `lang` 属性(默认 `css` )进行转换分析
205-
2. `css` 中规则:`css` 文件只能引用 `css` 文件,只会解析 `css` 后缀的文件。
206-
3. `scss``less``stylus` 中规则:`scss``less``stylus文件可以引用` `css` 文件、以及对应的 `scss``less` 文件或 `stylus` 文件,
207-
则对同名文件的 `css` 文件和对应的预处理器后缀文件进行转换分析。
204+
### ● Rules When Transforming Analysis
205+
1. In `sfc`, if `@import` specifies a suffix, the conversion analysis will be performed according to the suffix file,
206+
otherwise the conversion analysis will be performed according to the `lang` attribute of the current `script` tag (default `css`)
207+
2. Rules in `css`: `css` files can only reference `css` files, and only files with `css` suffixes will be parsed.
208+
3. Rules in `scss`, `less`, `stylus`: `scss`, `less`, `stylus` files can refer to` `css` files, and corresponding `scss` or `less` files or `stylus` files,
209+
The `css` file of the file with the same name and the corresponding preprocessor suffix file are converted and analyzed.
208210

209-
### sfc 中变量提取规则
210-
1. 对于 `script setup`, `unplugin-vue-cssvars` 会提取所有变量进行匹配。
211+
### Variable extraction rules in SFC
212+
1. For `script setup`, `unplugin-vue-cssvars` will extract all variables to match.
211213
````
212214
<script setup>
213215
const color = 'red'
214216
</script>
215217
````
216-
2. 对于 `composition api`, `unplugin-vue-cssvars` 会提取 `setup` 函数返回变量进行匹配。
218+
2. For `composition api`, `unplugin-vue-cssvars` will extract `setup` function return variables for matching.
217219
````
218220
<script>
219221
export default {
@@ -226,7 +228,7 @@ div[data-v-1dfefb04] {
226228
}
227229
</script>
228230
````
229-
3. 对于 `options api`, `unplugin-vue-cssvars` 会提取 `data` 函数返回变量进行匹配。
231+
3. For `options api`, `unplugin-vue-cssvars` will extract `data` function return variables for matching.
230232
````
231233
<script>
232234
export default {
@@ -239,24 +241,27 @@ div[data-v-1dfefb04] {
239241
}
240242
</script>
241243
````
242-
4. 对于普通的 `script`, `unplugin-vue-cssvars` 会提取所有变量进行匹配。
244+
4. For normal `script`, `unplugin-vue-cssvars` will extract all variables to match.
243245
````
244246
<script>
245247
const color = 'red'
246248
</script>
247249
````
248250

249-
### ● sfc 中变量冲突规则
250-
1. `sfc` 中有 `options api``composition api`, 所有变量会进行合并
251-
变量出现冲突以后面出现的(比如先写了 `options api`,后写 `composition api`,以 `composition api` 优先)优先
252-
2. `sfc` 中有 `script setup``options api``composition api`, 所有变量会进行合并,变量出现冲突以`script setup`优先
253-
3. `sfc` 中普通的 `script`,不会与`options api``composition api`同时存在
254-
4. `sfc` 中普通的 `script`若存在,则必存在`script setup`
255-
5. `sfc` 中普通的 `script``script setup` 所有变量会进行合并,变量出现冲突以`script setup`优先
251+
### ● Variable conflict rules in SFC
252+
1. In sfc, there are options API and composition API, and all variables will be merged. If there are conflicts in variables,
253+
the syntax that appears later will take precedence
254+
(for example, if options API is written first and composition API is written later, composition API takes precedence).
255+
2. There are `script setup`, `options api` and `composition api` in `sfc`, all variables will be merged,
256+
if there is a variable conflict, `script setup` will take precedence
257+
3. Ordinary `script` in `sfc` will not exist at the same time as `options api` and `composition api`
258+
4. If the normal `script` exists in `sfc`, there must be `script setup`
259+
5. Common `script` and `script setup` variables in `sfc` will be merged,
260+
if there is a variable conflict, `script setup` will take precedence
256261

257-
### 样式提升后的优先级
258-
1. `sfc` 开始,分析 `style` 标签中引用的 `css` 文件,按照 `css` 文件中的引用顺序,深度优先依次提升并注入到 `sfc` 中。
259-
2. 注入到 `sfc` 后,其优先级完全由 `@vue/compiler-dom` 的编译器决定。
262+
### Priority after style injection
263+
1. Starting from `sfc`, analyze the `css` files referenced in the `style` tag, and in accordance with the order of references in the `css` files, they will be promoted in depth-first order and injected into `sfc`.
264+
2. After being injected into `sfc`, its priority is completely determined by the compiler of `@vue/compiler-dom`.
260265

261266
## Thanks
262267
* [vue](https://github.com/vuejs/core)

0 commit comments

Comments
 (0)