diff --git a/config/config.ts b/config/config.ts index a24fd655..c518aa61 100644 --- a/config/config.ts +++ b/config/config.ts @@ -1,19 +1,13 @@ // https://umijs.org/config/ -import { defineConfig, utils } from 'umi'; +import { defineConfig } from 'umi'; import defaultSettings from './defaultSettings'; import proxy from './proxy'; -import webpackPlugin from './plugin.config'; -const { winPath } = utils; - -// preview.pro.ant.design only do not use in your production ; -// preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 -const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV, GA_KEY } = process.env; +const { REACT_APP_ENV } = process.env; export default defineConfig({ hash: true, antd: {}, - analytics: GA_KEY ? { ga: GA_KEY } : false, dva: { hmr: true, }, @@ -103,47 +97,9 @@ export default defineConfig({ // ...darkTheme, 'primary-color': defaultSettings.primaryColor, }, - define: { - REACT_APP_ENV: REACT_APP_ENV || false, - ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: - ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 - }, ignoreMomentLocale: true, - lessLoader: { - javascriptEnabled: true, - }, - cssLoader: { - modules: { - getLocalIdent: ( - context: { - resourcePath: string; - }, - _: string, - localName: string, - ) => { - if ( - context.resourcePath.includes('node_modules') || - context.resourcePath.includes('ant.design.pro.less') || - context.resourcePath.includes('global.less') - ) { - return localName; - } - const match = context.resourcePath.match(/src(.*)/); - if (match && match[1]) { - const antdProPath = match[1].replace('.less', ''); - const arr = winPath(antdProPath) - .split('/') - .map((a: string) => a.replace(/([A-Z])/g, '-$1')) - .map((a: string) => a.toLowerCase()); - return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-'); - } - return localName; - }, - }, - }, + proxy: proxy[REACT_APP_ENV || 'dev'], manifest: { basePath: '/', }, - proxy: proxy[REACT_APP_ENV || 'dev'], - chainWebpack: webpackPlugin, }); diff --git a/config/plugin.config.ts b/config/plugin.config.ts deleted file mode 100644 index aff2d476..00000000 --- a/config/plugin.config.ts +++ /dev/null @@ -1,65 +0,0 @@ -import path from 'path'; - -import * as IWebpackChainConfig from 'webpack-chain'; - -function getModulePackageName(module: { context: string }) { - if (!module.context) return null; - - const nodeModulesPath = path.join(__dirname, '../node_modules/'); - if (module.context.substring(0, nodeModulesPath.length) !== nodeModulesPath) { - return null; - } - - const moduleRelativePath = module.context.substring(nodeModulesPath.length); - const [moduleDirName] = moduleRelativePath.split(path.sep); - let packageName: string | null = moduleDirName; - // handle tree shaking - if (packageName && packageName.match('^_')) { - // eslint-disable-next-line prefer-destructuring - packageName = packageName.match(/^_(@?[^@]+)/)![1]; - } - return packageName; -} - -const webpackPlugin = (config: IWebpackChainConfig) => { - // optimize chunks - config.optimization - // share the same chunks across different modules - .runtimeChunk(false) - .splitChunks({ - chunks: 'async', - name: 'vendors', - maxInitialRequests: Infinity, - minSize: 0, - cacheGroups: { - vendors: { - test: (module: { context: string }) => { - const packageName = getModulePackageName(module) || ''; - if (packageName) { - return [ - 'bizcharts', - 'gg-editor', - 'g6', - '@antv', - 'l7', - 'gg-editor-core', - 'bizcharts-plugin-slider', - ].includes(packageName); - } - return false; - }, - name(module: { context: string }) { - const packageName = getModulePackageName(module); - if (packageName) { - if (['bizcharts', '@antv_data-set'].indexOf(packageName) >= 0) { - return 'viz'; // visualization package - } - } - return 'misc'; - }, - }, - }, - }); -}; - -export default webpackPlugin; diff --git a/mock/listTableList.ts b/mock/listTableList.ts index efc3224b..dfa5db08 100644 --- a/mock/listTableList.ts +++ b/mock/listTableList.ts @@ -41,7 +41,10 @@ function getRule(req: Request, res: Response, u: string) { const { current = 1, pageSize = 10 } = req.query; const params = (parse(realUrl, true).query as unknown) as TableListParams; - let dataSource = [...tableListDataSource].slice((current - 1) * pageSize, current * pageSize); + let dataSource = [...tableListDataSource].slice( + ((current as number) - 1) * (pageSize as number), + (current as number) * (pageSize as number), + ); if (params.sorter) { const s = params.sorter.split('_'); dataSource = dataSource.sort((prev, next) => { diff --git a/package.json b/package.json index b4a3b05c..d5bdae23 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "react": "^16.8.6", "react-dom": "^16.8.6", "react-helmet-async": "^1.0.4", - "umi": "^3.0.14", + "umi": "^3.1.0", "umi-request": "^1.0.8", "use-merge-value": "^1.0.1" }, @@ -88,7 +88,7 @@ "@types/react-helmet": "^5.0.13", "@umijs/fabric": "^2.0.5", "@umijs/plugin-blocks": "^2.0.5", - "@umijs/preset-ant-design-pro": "^1.0.1", + "@umijs/preset-ant-design-pro": "^1.2.0", "@umijs/preset-react": "^1.4.8", "@umijs/preset-ui": "^2.0.9", "carlo": "^0.9.46",