From 467767a6c56e99372a3b8fa80c93452fb886ad26 Mon Sep 17 00:00:00 2001 From: Baorong Li Date: Thu, 5 Mar 2020 23:22:02 +0800 Subject: [PATCH] upgrade umi@3 partly --- .umirc.js | 99 +++++++------------ package.json | 6 +- src/components/Layout/Bread.js | 3 +- src/components/Layout/Menu.js | 7 +- src/layouts/BaseLayout.js | 2 +- src/layouts/PrimaryLayout.js | 2 +- src/layouts/index.js | 2 +- src/pages/chart/ECharts/MainPageComponent.js | 2 +- src/pages/index.js | 2 +- src/pages/user/{$id => [id]}/index.js | 0 src/pages/user/{$id => [id]}/index.less | 0 src/pages/user/{$id => [id]}/models/detail.js | 0 src/pages/user/components/List.js | 2 +- src/utils/index.js | 8 +- 14 files changed, 55 insertions(+), 80 deletions(-) rename src/pages/user/{$id => [id]}/index.js (100%) rename src/pages/user/{$id => [id]}/index.less (100%) rename src/pages/user/{$id => [id]}/models/detail.js (100%) diff --git a/.umirc.js b/.umirc.js index 34df45c..70e30b7 100644 --- a/.umirc.js +++ b/.umirc.js @@ -1,76 +1,53 @@ // https://umijs.org/config/ import { resolve } from 'path' import { i18n } from './src/utils/config' +const fs = require('fs') +const path = require('path') +const lessToJs = require('less-vars-to-js') export default { publicPath: 'https://cdn.antd-admin.zuiidea.com/', hash: true, ignoreMomentLocale: true, targets: { ie: 9 }, - treeShaking: true, - plugins: [ - [ - // https://umijs.org/plugin/umi-plugin-react.html - 'umi-plugin-react', - { - dva: { immer: true }, - antd: true, - dynamicImport: { - webpackChunkName: true, - loadingComponent: './components/Loader/Loader', - }, - routes: { - exclude: [ - /model\.(j|t)sx?$/, - /service\.(j|t)sx?$/, - /models\//, - /components\//, - /services\//, - /chart\/Container\.js$/, - /chart\/ECharts\/.+Component\.js$/, - /chart\/ECharts\/.+ComPonent\.js$/, - /chart\/ECharts\/theme\/.+\.js$/, - /chart\/highCharts\/.+Component\.js$/, - /chart\/highCharts\/mapdata\/.+\.js$/, - /chart\/Recharts\/.+Component\.js$/, - /chart\/Recharts\/Container\.js$/, - ], - update: routes => { - if (!i18n) return routes + dva: { immer: true }, + antd: {}, + dynamicImport: { + loading: 'components/Loader/Loader' + }, + // TODO: routes need to be array + // routes: { + // update: routes => { + // if (!i18n) return routes - const newRoutes = [] - for (const item of routes[0].routes) { - newRoutes.push(item) - if (item.path) { - newRoutes.push( - Object.assign({}, item, { - path: - `/:lang(${i18n.languages - .map(item => item.key) - .join('|')})` + item.path, - }) - ) - } - } - routes[0].routes = newRoutes + // const newRoutes = [] + // for (const item of routes[0].routes) { + // newRoutes.push(item) + // if (item.path) { + // newRoutes.push( + // Object.assign({}, item, { + // path: + // `/:lang(${i18n.languages + // .map(item => item.key) + // .join('|')})` + item.path, + // }) + // ) + // } + // } + // routes[0].routes = newRoutes - return routes - }, - }, - dll: { - include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch', 'antd/es'], - }, - pwa: { - manifestOptions: { - srcPath: 'manifest.json', - }, - }, - }, - ], - ], + // return routes + // }, + // }, + // not support in umi@3 + // pwa: { + // manifestOptions: { + // srcPath: 'manifest.json', + // }, + // }, // Theme for antd // https://ant.design/docs/react/customize-theme - theme: './config/theme.config.js', + theme: lessToJs(fs.readFileSync(path.join(__dirname, './src/themes/default.less'), 'utf8')), // Webpack Configuration proxy: { '/api/v1/weather': { @@ -101,7 +78,7 @@ export default { 'lodash', ], ], - chainWebpack: function(config, { webpack }) { + chainWebpack: function (config, { webpack }) { config.merge({ optimization: { minimize: true, diff --git a/package.json b/package.json index cf5dae3..710478c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "MIT", "description": "An admin dashboard application demo built upon Ant Design and UmiJS", "dependencies": { - "@ant-design/compatible": "^0.0.1-rc.1", + "@ant-design/compatible": "^1.0.0", "@ant-design/icons": "^4.0.0", "@lingui/react": "^2.8.0", "ant-design-pro": "^2.3.0", @@ -43,6 +43,7 @@ "@lingui/babel-preset-react": "^2.8.2", "@lingui/cli": "^2.8.2", "@lingui/loader": "^2.8.2", + "@umijs/preset-react": "^1.3.7", "babel-core": "7.0.0-bridge.0", "babel-eslint": "^10.0.1", "babel-plugin-dev-expression": "^0.2.1", @@ -66,8 +67,7 @@ "stylelint": "^13.0.0", "stylelint-config-prettier": "^8.0.0", "stylelint-config-standard": "^20.0.0", - "umi": "^2.13.0", - "umi-plugin-react": "^1.15.0" + "umi": "^3.0.0" }, "engines": { "node": ">= 10.0.0" diff --git a/src/components/Layout/Bread.js b/src/components/Layout/Bread.js index 45ee4de..a23595f 100644 --- a/src/components/Layout/Bread.js +++ b/src/components/Layout/Bread.js @@ -1,8 +1,7 @@ import React, { PureComponent, Fragment } from 'react' import PropTypes from 'prop-types' import { Breadcrumb } from 'antd' -import Link from 'umi/navlink' -import withRouter from 'umi/withRouter' +import { Link, withRouter } from 'umi' import { Icon as LegacyIcon } from '@ant-design/compatible' import { withI18n } from '@lingui/react' import { pathMatchRegexp, queryAncestors, addLangPrefix } from 'utils' diff --git a/src/components/Layout/Menu.js b/src/components/Layout/Menu.js index 16297b1..b67f13e 100644 --- a/src/components/Layout/Menu.js +++ b/src/components/Layout/Menu.js @@ -2,8 +2,7 @@ import React, { PureComponent, Fragment } from 'react' import PropTypes from 'prop-types' import { Icon as LegacyIcon } from '@ant-design/compatible' import { Menu } from 'antd' -import Navlink from 'umi/navlink' -import withRouter from 'umi/withRouter' +import { NavLink, withRouter } from 'umi' import { arrayToTree, queryAncestors, @@ -58,10 +57,10 @@ class SiderMenu extends PureComponent { } return ( - + {item.icon && } {item.name} - + ) }) diff --git a/src/layouts/BaseLayout.js b/src/layouts/BaseLayout.js index d18d453..ef5b143 100644 --- a/src/layouts/BaseLayout.js +++ b/src/layouts/BaseLayout.js @@ -6,7 +6,7 @@ import { Loader } from 'components' import { queryLayout } from 'utils' import NProgress from 'nprogress' import config from 'utils/config' -import withRouter from 'umi/withRouter' +import { withRouter } from 'umi' import PublicLayout from './PublicLayout' import PrimaryLayout from './PrimaryLayout' diff --git a/src/layouts/PrimaryLayout.js b/src/layouts/PrimaryLayout.js index 978598f..27196e9 100644 --- a/src/layouts/PrimaryLayout.js +++ b/src/layouts/PrimaryLayout.js @@ -2,7 +2,7 @@ /* global document */ import React, { PureComponent, Fragment } from 'react' import PropTypes from 'prop-types' -import withRouter from 'umi/withRouter' +import { withRouter } from 'umi' import { connect } from 'dva' import { MyLayout } from 'components' import { BackTop, Layout, Drawer } from 'antd' diff --git a/src/layouts/index.js b/src/layouts/index.js index 8c53540..1064650 100644 --- a/src/layouts/index.js +++ b/src/layouts/index.js @@ -1,5 +1,5 @@ import React, { Component } from 'react' -import withRouter from 'umi/withRouter' +import { withRouter } from 'umi' import { ConfigProvider } from 'antd' import { I18nProvider } from '@lingui/react' import { langFromPath, defaultLanguage } from 'utils' diff --git a/src/pages/chart/ECharts/MainPageComponent.js b/src/pages/chart/ECharts/MainPageComponent.js index 29bf2bc..ed0a5cd 100644 --- a/src/pages/chart/ECharts/MainPageComponent.js +++ b/src/pages/chart/ECharts/MainPageComponent.js @@ -1,6 +1,6 @@ import React from 'react' import AdSense from 'react-adsense' -import { Link } from 'react-router' +import { Link } from 'umi' import DynamicChartComponent from './DynamicChartComponent.js' const MainPageComponent = () => { diff --git a/src/pages/index.js b/src/pages/index.js index 5cbc165..b34ad05 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -1,5 +1,5 @@ import React, { PureComponent } from 'react' -import Redirect from 'umi/redirect' +import { Redirect } from 'umi' import { withI18n } from '@lingui/react' @withI18n() diff --git a/src/pages/user/$id/index.js b/src/pages/user/[id]/index.js similarity index 100% rename from src/pages/user/$id/index.js rename to src/pages/user/[id]/index.js diff --git a/src/pages/user/$id/index.less b/src/pages/user/[id]/index.less similarity index 100% rename from src/pages/user/$id/index.less rename to src/pages/user/[id]/index.less diff --git a/src/pages/user/$id/models/detail.js b/src/pages/user/[id]/models/detail.js similarity index 100% rename from src/pages/user/$id/models/detail.js rename to src/pages/user/[id]/models/detail.js diff --git a/src/pages/user/components/List.js b/src/pages/user/components/List.js index 1e7c45d..ff73f0f 100644 --- a/src/pages/user/components/List.js +++ b/src/pages/user/components/List.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types' import { Table, Modal, Avatar } from 'antd' import { DropOption } from 'components' import { Trans, withI18n } from '@lingui/react' -import Link from 'umi/link' +import { Link } from 'umi' import styles from './List.less' const { confirm } = Modal diff --git a/src/utils/index.js b/src/utils/index.js index 015f00c..4311ac8 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,5 +1,5 @@ import { cloneDeep, isString, flow, curry } from 'lodash' -import umiRouter from 'umi/router' +import { history } from 'umi' import pathToRegexp from 'path-to-regexp' import { i18n } from './config' import moment from 'moment' @@ -140,11 +140,11 @@ const routerAddLangPrefix = params => { /** * Adjust the router to automatically add the current language prefix before the pathname in push and replace. */ -const myRouter = { ...umiRouter } +const myRouter = { ...history } myRouter.push = flow( routerAddLangPrefix, - umiRouter.push + history.push ) myRouter.replace = flow( @@ -266,7 +266,7 @@ export function getLocale() { export function setLocale(language) { if (getLocale() !== language) { moment.locale(language === 'zh' ? 'zh-cn' : language) - umiRouter.push({ + history.push({ pathname: `/${language}${deLangPrefix(window.location.pathname)}`, search: window.location.search, })