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');
export default {
// add for transfer to umi
plugins: [
'umi-plugin-dva',
'umi-plugin-locale',
// TODO 决定是否使用约定路由,如果使用配置路由那么 umi-plugin-routes 可以去掉了
// [
// 'umi-plugin-routes',
// {
// exclude: [/\.test\.js/],
// update(routes) {
// return [...pageRoutes, ...routes];
// },
// },
// ],
['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',
],
}],
],
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
antd: true, // use antd, default is true
},
// 路由配置
routes: pageRoutes,
theme: {
'card-actions-background': '#f5f8fa',
},
// entry: 'src/index.js', // TODO remove
extraBabelPlugins: [['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]],
env: {
development: {
extraBabelPlugins: ['dva-hmr'],
},
},
externals: {
'@antv/data-set': 'DataSet',
rollbar: 'rollbar',
......@@ -62,15 +54,19 @@ export default {
) {
return localName;
}
const antdProPath = context.resourcePath.match(/src(.*)/)[1].replace('.less', '');
const arr = antdProPath
.split('/')
.map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
const match = context.resourcePath.match(/src(.*)/);
if (match && match[1]) {
const antdProPath = match[1].replace('.less', '');
const arr = antdProPath
.split('/')
.map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
} else {
return localName;
}
},
},
disableFastClick: true,
manifest: {
name: 'ant-design-pro',
background_color: '#FFF',
......@@ -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 @@
"scripts": {
"precommit": "npm run lint-staged",
"presite": "npm run generate-mock && cd functions && npm install",
"start": "cross-env ESLINT=none umi dev",
"start:no-mock": "cross-env MOCK=none ESLINT=none umi dev",
"build": "cross-env ESLINT=none umi build",
"start": "cross-env umi dev",
"start:no-mock": "cross-env MOCK=none umi dev",
"build": "cross-env umi build",
"site": "npm run presite && npm run build && firebase deploy",
"analyze": "cross-env ANALYZE=1 umi build",
"lint:style": "stylelint \"src/**/*.less\" --syntax less",
......@@ -55,10 +55,6 @@
"antd-pro-merge-less": "^0.0.2",
"antd-theme-webpack-plugin": "^1.0.8",
"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",
"cross-env": "^5.1.1",
"cross-port-killer": "^1.0.1",
......@@ -86,10 +82,8 @@
"stylelint": "^9.4.0",
"stylelint-config-prettier": "^3.0.4",
"stylelint-config-standard": "^18.0.0",
"umi": "^1.3.15",
"umi-plugin-dva": "^0.9.1",
"umi-plugin-locale": "^1.0.1",
"umi-plugin-routes": "^0.1.5"
"umi": "^2.0.0-0",
"umi-plugin-react": "^1.0.0-0"
},
"optionalDependencies": {
"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