diff --git a/config/config.js b/config/config.js index 02c4c1b78aa6d6fc00a7c3ef711764f14e8cc3c0..fbe7b2ce6afb2e27a3b9850ee0bb32d36d69ab61 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 0000000000000000000000000000000000000000..27879fdd25927da27fd88ffcfa0bc424e85aa5f9 --- /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;