Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 1.x support theme config primary/secondary color #1435

Merged
merged 10 commits into from Feb 19, 2019

Conversation

imsobear
Copy link
Collaborator

@imsobear imsobear commented Feb 3, 2019

No description provided.

@imsobear
Copy link
Collaborator Author

imsobear commented Feb 3, 2019

ice-scripts 里支持两种方式配置主题:

  1. 配置 buildConfig.theme 对应一个主题包的 variables.scss
  2. 配置 themeConfig.primary-color 对应一个主题变量,然后会根据配置推导出一系列颜色变量,优先级高于 variables.scss

整体流程,首先 theme 变量文件里的内容(由配置平台产生):

// theme/variables.scss
$color-brand1-6: #f60;
// 这里会将原先的 $btn-primary-bg-color: $color-brand1-6 编译掉
// 这里如果不编译掉理论上就不会有问题(不清楚为什么会编译掉)
$btn-primary-bg-color: #f60;

然后根据用户配置的 primary-color 正常情况下会生成下面的内容:

// 1.x 会生成这几个颜色
$color-brand1-1: #f20;
$color-brand1-6: #555;
$color-brand1-9: #f90;
$color-link-1: $color-brand1-6;
$color-link-2: $color-brand1-6;
$color-link-3: $color-brand1-9;

接着构建时 primary-color 生成的变量优先级高于 theme 包里定义的变量,这时候代码里直接使用 $color-brand1-1 的地方会被正确覆盖,但是诸如上面 $btn-primary-bg-color 的变量已经被固化了,无法被覆盖,这样根据不同的情况就会出现两种主题色。

image

解决这个问题有下面几种方法:

  1. theme/variables.scss 里只出现用户在配置平台上改过的变量,可能会影响其他地方,可能性较低
  2. 约束用户 theme 和 primary-color 不允许同时使用,这两个方案单独使用都是没有问题的,这个方案比较合理但对用户使用有了限制
  3. 根据 primary-color 生成的变量里需要补齐所有用到这几个变量的地方,类似如图 0.x 的这个做法,这个方案比较恶心但是用户使用起来是最无脑的

image

@imsobear
Copy link
Collaborator Author

结论:theme 和 primary-color 不允许同时使用

@imsobear imsobear merged commit ecd3796 into master Feb 19, 2019
@delete-merged-branch delete-merged-branch bot deleted the feat-1.x-support-themeConfig branch February 19, 2019 08:55
@panpanbear
Copy link

panpanbear commented Dec 1, 2020

设置主题色后,就报很多以下类似的错误,哪位大佬知道这是怎么回事啊?

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable: "$menu-shadow".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants