Explorar o código

:wrench: improve pro config.ts

afc163 %!s(int64=6) %!d(string=hai) anos
pai
achega
b51cd57548
Modificáronse 2 ficheiros con 27 adicións e 47 borrados
  1. 24 45
      config/config.ts
  2. 3 2
      package.json

+ 24 - 45
config/config.ts

@@ -2,7 +2,6 @@ import { IConfig, IPlugin } from 'umi-types';
 
 import defaultSettings from './defaultSettings';
 // https://umijs.org/config/
-import os from 'os';
 import slash from 'slash2';
 import webpackPlugin from './plugin.config';
 
@@ -10,8 +9,10 @@ const { pwa, primaryColor } = defaultSettings;
 
 // 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 } = process.env;
+
+const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
 
-const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST, NODE_ENV } = process.env;
 const plugins: IPlugin[] = [
   [
     'umi-plugin-react',
@@ -41,15 +42,10 @@ const plugins: IPlugin[] = [
             },
           }
         : false,
-      ...(!TEST && os.platform() === 'darwin'
-        ? {
-            dll: {
-              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
-              exclude: ['@babel/runtime', 'netlify-lambda'],
-            },
-            hardSource: false,
-          }
-        : {}),
+      dll: {
+        include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
+        exclude: ['@babel/runtime', 'netlify-lambda'],
+      },
     },
   ],
   [
@@ -61,10 +57,10 @@ const plugins: IPlugin[] = [
       autoAddMenu: true,
     },
   ],
-]; // 针对 preview.pro.ant.design 的 GA 统计代码
-// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
+];
 
-if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
+// 针对 preview.pro.ant.design 的 GA 统计代码
+if (isAntDesignProPreview) {
   plugins.push([
     'umi-plugin-ga',
     {
@@ -73,34 +69,17 @@ if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
   ]);
 }
 
-const uglifyJSOptions =
-  NODE_ENV === 'production'
-    ? {
-        uglifyOptions: {
-          // remove console.* except console.error
-          compress: {
-            drop_console: true,
-            pure_funcs: ['console.error'],
-          },
-        },
-      }
-    : {};
 export default {
-  // add for transfer to umi
   plugins,
-  define: {
-    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 专用环境变量,请不要在你的项目中使用它。
-  },
   block: {
     defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
   },
-  treeShaking: true,
+  hash: true,
   targets: {
     ie: 11,
   },
-  devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
-  // 路由配置
+  devtool: isAntDesignProPreview ? 'source-map' : false,
+  // umi routes: https://umijs.org/zh/guide/router.html
   routes: [
     {
       path: '/',
@@ -117,18 +96,10 @@ export default {
       ],
     },
   ],
-  // Theme for antd
-  // https://ant.design/docs/react/customize-theme-cn
+  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
   theme: {
     'primary-color': primaryColor,
   },
-  // proxy: {
-  //   '/server/api/': {
-  //     target: 'https://preview.pro.ant.design/',
-  //     changeOrigin: true,
-  //     pathRewrite: { '^/server': '' },
-  //   },
-  // },
   ignoreMomentLocale: true,
   lessLoaderOptions: {
     javascriptEnabled: true,
@@ -140,7 +111,7 @@ export default {
       context: {
         resourcePath: string;
       },
-      localIdentName: string,
+      _: string,
       localName: string,
     ) => {
       if (
@@ -168,6 +139,14 @@ export default {
   manifest: {
     basePath: '/',
   },
-  uglifyJSOptions,
   chainWebpack: webpackPlugin,
+  /*
+  proxy: {
+    '/server/api/': {
+      target: 'https://preview.pro.ant.design/',
+      changeOrigin: true,
+      pathRewrite: { '^/server': '' },
+    },
+  },
+  */
 } as IConfig;

+ 3 - 2
package.json

@@ -78,7 +78,8 @@
     "umi-plugin-ga": "^1.1.3",
     "umi-plugin-pro-block": "^1.3.2",
     "umi-plugin-react": "^1.8.2",
-    "umi-request": "^1.0.7"
+    "umi-request": "^1.0.7",
+    "umi-types": "^0.3.7"
   },
   "devDependencies": {
     "@ant-design/colors": "^3.1.0",
@@ -158,4 +159,4 @@
       "create-umi"
     ]
   }
-}
+}