Commit f97a8042 authored by sorrycc's avatar sorrycc Committed by 陈帅

feat: migrate to umi@2

parent 2ba897f0
...@@ -7,38 +7,30 @@ const path = require('path'); ...@@ -7,38 +7,30 @@ const path = require('path');
export default { export default {
// add for transfer to umi // add for transfer to umi
plugins: [ plugins: [
'umi-plugin-dva', ['umi-plugin-react', {
'umi-plugin-locale', antd: true,
// TODO 决定是否使用约定路由,如果使用配置路由那么 umi-plugin-routes 可以去掉了 dva: {
// [ hmr: true,
// 'umi-plugin-routes', },
// {
// exclude: [/\.test\.js/],
// update(routes) {
// return [...pageRoutes, ...routes];
// },
// },
// ],
],
locale: { locale: {
enable: true, // default false enable: true, // default false
default: 'zh-CN', // default zh-CN default: 'zh-CN', // default zh-CN
baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
antd: true, // use antd, default is true
}, },
dll: [
'dva',
'dva/router',
'dva/saga',
'dva/fetch',
],
}],
],
// 路由配置 // 路由配置
routes: pageRoutes, routes: pageRoutes,
theme: { theme: {
'card-actions-background': '#f5f8fa', 'card-actions-background': '#f5f8fa',
}, },
// entry: 'src/index.js', // TODO remove
extraBabelPlugins: [['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]],
env: {
development: {
extraBabelPlugins: ['dva-hmr'],
},
},
externals: { externals: {
'@antv/data-set': 'DataSet', '@antv/data-set': 'DataSet',
rollbar: 'rollbar', rollbar: 'rollbar',
...@@ -62,15 +54,19 @@ export default { ...@@ -62,15 +54,19 @@ export default {
) { ) {
return localName; return localName;
} }
const antdProPath = context.resourcePath.match(/src(.*)/)[1].replace('.less', ''); const match = context.resourcePath.match(/src(.*)/);
if (match && match[1]) {
const antdProPath = match[1].replace('.less', '');
const arr = antdProPath const arr = antdProPath
.split('/') .split('/')
.map(a => a.replace(/([A-Z])/g, '-$1')) .map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase()); .map(a => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-'); return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
} else {
return localName;
}
}, },
}, },
disableFastClick: true,
manifest: { manifest: {
name: 'ant-design-pro', name: 'ant-design-pro',
background_color: '#FFF', background_color: '#FFF',
...@@ -85,4 +81,30 @@ export default { ...@@ -85,4 +81,30 @@ 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',
// }]);
},
}; };
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
"scripts": { "scripts": {
"precommit": "npm run lint-staged", "precommit": "npm run lint-staged",
"presite": "npm run generate-mock && cd functions && npm install", "presite": "npm run generate-mock && cd functions && npm install",
"start": "cross-env ESLINT=none umi dev", "start": "cross-env umi dev",
"start:no-mock": "cross-env MOCK=none ESLINT=none umi dev", "start:no-mock": "cross-env MOCK=none umi dev",
"build": "cross-env ESLINT=none umi build", "build": "cross-env umi build",
"site": "npm run presite && npm run build && firebase deploy", "site": "npm run presite && npm run build && firebase deploy",
"analyze": "cross-env ANALYZE=1 umi build", "analyze": "cross-env ANALYZE=1 umi build",
"lint:style": "stylelint \"src/**/*.less\" --syntax less", "lint:style": "stylelint \"src/**/*.less\" --syntax less",
...@@ -55,10 +55,6 @@ ...@@ -55,10 +55,6 @@
"antd-pro-merge-less": "^0.0.2", "antd-pro-merge-less": "^0.0.2",
"antd-theme-webpack-plugin": "^1.0.8", "antd-theme-webpack-plugin": "^1.0.8",
"babel-eslint": "^8.2.6", "babel-eslint": "^8.2.6",
"babel-plugin-dva-hmr": "^0.4.1",
"babel-plugin-import": "^1.8.0",
"babel-plugin-module-resolver": "^3.1.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-runtime": "^6.9.2", "babel-runtime": "^6.9.2",
"cross-env": "^5.1.1", "cross-env": "^5.1.1",
"cross-port-killer": "^1.0.1", "cross-port-killer": "^1.0.1",
...@@ -86,10 +82,8 @@ ...@@ -86,10 +82,8 @@
"stylelint": "^9.4.0", "stylelint": "^9.4.0",
"stylelint-config-prettier": "^3.0.4", "stylelint-config-prettier": "^3.0.4",
"stylelint-config-standard": "^18.0.0", "stylelint-config-standard": "^18.0.0",
"umi": "^1.3.15", "umi": "^2.0.0-0",
"umi-plugin-dva": "^0.9.1", "umi-plugin-react": "^1.0.0-0"
"umi-plugin-locale": "^1.0.1",
"umi-plugin-routes": "^0.1.5"
}, },
"optionalDependencies": { "optionalDependencies": {
"puppeteer": "^1.6.0" "puppeteer": "^1.6.0"
......
import AntDesignThemePlugin from 'antd-theme-webpack-plugin';
import MergeLessPlugin from 'antd-pro-merge-less';
const path = require('path');
export default webpackConfig => {
// 将所有 less 合并为一个供 themePlugin使用
const outFile = path.join(__dirname, './.temp/ant-design-pro.less');
const stylesDir = path.join(__dirname, './src/');
const mergeLessPlugin = new MergeLessPlugin({
stylesDir,
outFile,
});
const options = {
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',
};
const themePlugin = new AntDesignThemePlugin(options);
// in config object
webpackConfig.plugins.push(mergeLessPlugin);
webpackConfig.plugins.push(themePlugin);
return webpackConfig;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment