Просмотр исходного кода

🔧 config: less config (#6328)

* 🔧 config: less config

* 📌 versions: up umi version

* fix tsc error
陈帅 5 лет назад
Родитель
Сommit
d124863b69
4 измененных файлов с 9 добавлено и 115 удалено
  1. 3 47
      config/config.ts
  2. 0 65
      config/plugin.config.ts
  3. 4 1
      mock/listTableList.ts
  4. 2 2
      package.json

+ 3 - 47
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,
 });

+ 0 - 65
config/plugin.config.ts

@@ -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;

+ 4 - 1
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) => {

+ 2 - 2
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",