From b51cd57548cd3e2ae66c0f3cbbb86bf4084a6e46 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 6 Jun 2019 11:44:51 +0800 Subject: [PATCH] :wrench: improve pro config.ts --- config/config.ts | 69 +++++++++++++++++------------------------------- package.json | 5 ++-- 2 files changed, 27 insertions(+), 47 deletions(-) diff --git a/config/config.ts b/config/config.ts index ee881103..5829f6c5 100644 --- a/config/config.ts +++ b/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; diff --git a/package.json b/package.json index 7cd6eba6..2851aae7 100644 --- a/package.json +++ b/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" ] } -} \ No newline at end of file +} -- GitLab