Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
当前组件库中组件的设计是将所有功能的样式文件书写到一个文件中,在进行组件使用的时候,css 相关的 tree shake 并不能最优化的处理。
基于上面的问题,可以通过将css 进行拆分,按照变体的方式实现组件,然后在编译阶段根据 props 按需引入样式文件。从而解决用户反馈的”我只使用了 Button 组件的 type 属性,为什么要把所有 css 内容进行打包“的问题。
css 文件的拆分方式
index.scss:组件的入口
layout.scss: 组件的基础布局
[属性名].scss: 组件属性的入口
[属性名-属性值].scss:组件具体的变体实现
css 的层叠优先级
为了能正确的加载 css 文件,需要开发过程中显示的组织好 css 类的层叠级别。所以需要再组件中设置 css.json 文件,根据此文件来处理 css 层叠优先级。
具体格式:
说明:
default
声明组件的默认变体。properties
声明属性变体的层叠优先级,数字越大层叠优先级越高。