Skip to content

Commit 7e93772

Browse files
committed
chore: update todo
1 parent 9b8d65d commit 7e93772

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

README.ZH-CN.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,9 @@ export interface Options {
130130
revoke?: boolean
131131
}
132132
```
133-
133+
## Tips TODO
134+
### 转换分析时的约定规则
135+
1. sfc 中,如果 @import 指定了后缀,则根据后缀的文件进行转换分析,否则根据当前 script 标签的 lang 属性(默认css)进行转换分析。
136+
2. css中规则:css文件只能引用 css 文件,只会解析 css 后缀的文件
137+
3. scss、less、stylus 中规则:scss、less、stylus文件可以引用 css 文件、以及对应的scss或less文件或stylus文件,则对同名文件的css文件和对应的预处理器后缀文件进行转换分析
134138
## Thanks TODO

packages/core/css/pre-process-css.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,10 @@ export function preProcessCSS(options: SearchGlobOptions): ICSSFileMap {
144144

145145
const cssFiles: ICSSFileMap = new Map()
146146

147-
// ⭐TODO: 同名文件,不同後綴怎麽處理? 優先級怎麽定?
148147
for (const file of files) {
149-
// ⭐⭐TODO: 读取内容,後綴怎麽處理?
150148
const code = fs.readFileSync(resolve(rootDir!, file), { encoding: 'utf-8' })
151149
// parse css ast
150+
// css中规则:css文件只能引用 css 文件
152151
if (file.endsWith(`.${SUPPORT_FILE.CSS}`)) {
153152
const cssAst = csstree.parse(code)
154153
let absoluteFilePath = resolve(parse(file).dir, parse(file).base)
@@ -173,12 +172,22 @@ export function preProcessCSS(options: SearchGlobOptions): ICSSFileMap {
173172
})
174173
})
175174
}
175+
// scss、less、stylus 中规则:scss、less、stylus文件可以引用 css 文件、
176+
// 以及对应的scss或less文件或stylus文件,则对同名文件的css文件和对应的预处理器后缀文件进行转换分析
177+
// ⭐⭐TODO: 读取内容,後綴怎麽處理?
178+
// ⭐TODO: 同名文件,不同後綴怎麽處理? 優先級怎麽定?
179+
180+
// ⭐TODO: 支持 scss
181+
// if (file.endsWith(`.${SUPPORT_FILE.SASS}`)) { /* empty */ }
176182

177183
// ⭐TODO: 支持 sass
178184
// if (file.endsWith(`.${SUPPORT_FILE.SASS}`)) { /* empty */ }
179185

180186
// ⭐TODO: 支持 less
181187
// if (file.endsWith(`.${SUPPORT_FILE.LESS}`)) { /* empty */ }
188+
189+
// ⭐TODO: 支持 stylus
190+
// if (file.endsWith(`.${SUPPORT_FILE.SASS}`)) { /* empty */ }
182191
}
183192
return cssFiles
184193
}

packages/core/css/process-css.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export const createCSSModule = (descriptor: SFCDescriptor, id: string, cssFiles:
3636
// 根据其 ast,获取 @import 信息
3737
walkCSSTree(cssAst, (importer) => {
3838
// 添加后缀
39-
const key = completeSuffix(transformSymbol(path.resolve(path.parse(id).dir, importer)))
39+
// sfc中规则:如果@import 指定了后缀,则根据后缀,否则根据当前 script 标签的 lang 属性(默认css)
40+
const key = completeSuffix(transformSymbol(path.resolve(path.parse(id).dir, importer)), descriptor.styles[i].lang)
4041
// 根据 @import 信息,从 cssFiles 中,递归的获取所有在预处理时生成的 cssvars 样式
4142
getCSSFileRecursion(key, cssFiles, (res: ICSSFile) => {
4243
importModule.push(res)

play/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default {
6666
</div>
6767
</template>
6868

69-
<style scoped>
69+
<style scoped lang="scss">
7070
@import "./assets/test";
7171
/* div {
7272
color: v-bind(color2)

utils/constant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
export const NAME = 'unplugin-vue-cssvars'
2-
export const SUPPORT_FILE_LIST = ['**/**.css', '**/**.less', '**/**.scss']
2+
export const SUPPORT_FILE_LIST = ['**/**.css', '**/**.less', '**/**.scss', '**/**.stylus']
33
export const FG_IGNORE_LIST = ['**/node_modules/**', '**/dist/**', '**/.git/**']
44
export const SUPPORT_FILE = {
55
CSS: 'css',
66
LESS: 'less',
77
SASS: 'sass',
8+
STYLUS: 'stylus',
89
}
910
export const DEFAULT_INCLUDE_REG = [/\.vue$/]
1011
export const DEFAULT_EXCLUDE_REG = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.dist[\\/]/]

utils/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { SUPPORT_FILE } from './constant'
2+
13
export * from './log'
24
export * from './constant'
3-
export const completeSuffix = (fileName: string, suffix = 'css') => {
5+
export const completeSuffix = (fileName: string, suffix = SUPPORT_FILE.CSS) => {
46
return !fileName.endsWith(`.${suffix}`) ? `${fileName}.${suffix}` : fileName
57
}
68
export const extend = <

0 commit comments

Comments
 (0)