From 8f4c3f6f4092f4c93f534079c71798042a8c9587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Tue, 14 Aug 2018 10:13:58 +0800 Subject: [PATCH] fix change theme plugin --- config/config.js | 57 ++++++++++++----------------------------- config/plugin.config.js | 31 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 41 deletions(-) create mode 100644 config/plugin.config.js diff --git a/config/config.js b/config/config.js index 02c4c1b7..fbe7b2ce 100644 --- a/config/config.js +++ b/config/config.js @@ -2,28 +2,27 @@ // https://umijs.org/config/ const pageRoutes = require('./router.config'); +const webpackplugin = require('./plugin.config'); const path = require('path'); export default { // add for transfer to umi plugins: [ - ['umi-plugin-react', { - antd: true, - dva: { - hmr: true, - }, - locale: { - enable: true, // default false - default: 'zh-CN', // default zh-CN - baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default + [ + 'umi-plugin-react', + { + antd: true, + dva: { + hmr: true, + }, + locale: { + enable: true, // default false + default: 'zh-CN', // default zh-CN + baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default + }, + dll: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'], }, - dll: [ - 'dva', - 'dva/router', - 'dva/saga', - 'dva/fetch', - ], - }], + ], ], // 路由配置 routes: pageRoutes, @@ -82,29 +81,5 @@ export default { ], }, - chainWebpack(config) { - const AntDesignThemePlugin = require('antd-theme-webpack-plugin'); - const MergeLessPlugin = require('antd-pro-merge-less'); - - // 将所有 less 合并为一个供 themePlugin使用 - const outFile = path.join(__dirname, './.temp/ant-design-pro.less'); - const stylesDir = path.join(__dirname, './src/'); - // config - // .plugin('merge-less') - // .use(MergeLessPlugin, [{ - // stylesDir, - // outFile, - // }]); - - // config - // .plugin('ant-design-theme') - // .use(AntDesignThemePlugin, [{ - // antDir: path.join(__dirname, './node_modules/antd'), - // stylesDir, - // varFile: path.join(__dirname, './node_modules/antd/lib/style/themes/default.less'), - // mainLessFile: outFile, - // themeVariables: ['@primary-color'], - // indexFileName: 'index.html', - // }]); - }, + chainWebpack: webpackplugin, }; diff --git a/config/plugin.config.js b/config/plugin.config.js new file mode 100644 index 00000000..27879fdd --- /dev/null +++ b/config/plugin.config.js @@ -0,0 +1,31 @@ +// Change theme plugin + +const MergeLessPlugin = require('antd-pro-merge-less'); +const AntDesignThemePlugin = require('antd-theme-webpack-plugin'); +const path = require('path'); + +const plugin = config => { + // 将所有 less 合并为一个供 themePlugin使用 + const outFile = path.join(__dirname, '../.temp/ant-design-pro.less'); + const stylesDir = path.join(__dirname, '../src/'); + + config.plugin('merge-less').use(MergeLessPlugin, [ + { + stylesDir, + outFile, + }, + ]); + + config.plugin('ant-design-theme').use(AntDesignThemePlugin, [ + { + antDir: path.join(__dirname, '../node_modules/antd'), + stylesDir, + varFile: path.join(__dirname, '../node_modules/antd/lib/style/themes/default.less'), + mainLessFile: outFile, + themeVariables: ['@primary-color'], + indexFileName: 'index.html', + }, + ]); +}; + +module.exports = plugin; -- GitLab