From 84873c8835ebf95c938c9f840fe5f609c9e49291 Mon Sep 17 00:00:00 2001 From: wangyi <724003548@qq.com> Date: Mon, 5 Aug 2019 10:42:57 +0800 Subject: [PATCH] feat(antdsite): add themeConfig.themeColors and you can set theme colors of ant design. --- .../antdsite/__default__/default-config.js | 5 +-- .../lib/gatsby/onCreateWebpackConfig.js | 12 ++++--- packages/antdsite/lib/util.js | 32 +++++++++++++++++-- .../src/default-theme/assets/common.less | 5 +++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/packages/antdsite/__default__/default-config.js b/packages/antdsite/__default__/default-config.js index 34d437a..2834343 100644 --- a/packages/antdsite/__default__/default-config.js +++ b/packages/antdsite/__default__/default-config.js @@ -7,6 +7,7 @@ module.exports = { lang: 'en-US', head: [], themeConfig: { + themeColors: null, repo: null, docsRepo: null, docsDir: 'docs', @@ -20,6 +21,6 @@ module.exports = { showBackToTop: true, maxTocDeep: 3, search: true, - searchMaxSuggestions: 10, - }, + searchMaxSuggestions: 10 + } }; diff --git a/packages/antdsite/lib/gatsby/onCreateWebpackConfig.js b/packages/antdsite/lib/gatsby/onCreateWebpackConfig.js index e4984a6..eafb43a 100644 --- a/packages/antdsite/lib/gatsby/onCreateWebpackConfig.js +++ b/packages/antdsite/lib/gatsby/onCreateWebpackConfig.js @@ -1,17 +1,19 @@ -const { resolveLayouts } = require('../util'); +const { resolveLayouts, setThemeColors } = require('../util'); module.exports = ({ stage, actions, loaders }) => { resolveLayouts(actions); + setThemeColors(actions); + if (stage === 'develop') { actions.setWebpackConfig({ module: { rules: [ { test: /react-hot-loader/, - use: [loaders.js()], - }, - ], - }, + use: [loaders.js()] + } + ] + } }); } }; diff --git a/packages/antdsite/lib/util.js b/packages/antdsite/lib/util.js index 38daa0a..b48aba1 100644 --- a/packages/antdsite/lib/util.js +++ b/packages/antdsite/lib/util.js @@ -117,9 +117,35 @@ module.exports.resolveLayouts = function(actions) { actions.setWebpackConfig({ resolve: { alias: { - [`antdsite-${layout}`]: layoutPath, - }, - }, + [`antdsite-${layout}`]: layoutPath + } + } }); }); }; + +module.exports.setThemeColors = function(actions) { + const config = module.exports.getFinalConfig(); + const { themeColors } = config.themeConfig; + + if (themeColors) { + actions.setWebpackConfig({ + module: { + rules: [ + { + test: /\.less$/, + use: [ + { + loader: 'less-loader', // compiles Less to CSS + options: { + modifyVars: themeColors, + javascriptEnabled: true + } + } + ] + } + ] + } + }); + } +}; diff --git a/packages/antdsite/src/default-theme/assets/common.less b/packages/antdsite/src/default-theme/assets/common.less index 43f5cda..941c4ef 100644 --- a/packages/antdsite/src/default-theme/assets/common.less +++ b/packages/antdsite/src/default-theme/assets/common.less @@ -145,3 +145,8 @@ a { .drawer { z-index: 1029; } + +// fix back-top icon background-size 1% bug when modifying the theme. +.ant-back-top-icon { + background-size: 100% 100% !important; +}