Bläddra i källkod

feat: Officially traded will use cdn to optimize bizchart (#3535)

陈帅 6 år sedan
förälder
incheckning
65e822ea54
2 ändrade filer med 14 tillägg och 4 borttagningar
  1. 8 3
      config/config.js
  2. 6 1
      src/pages/document.ejs

+ 8 - 3
config/config.js

@@ -6,6 +6,7 @@ import defaultSettings from '../src/defaultSettings';
 import slash from 'slash2';
 
 const { pwa, primaryColor } = defaultSettings;
+const { NODE_ENV, APP_TYPE, TEST } = process.env;
 
 const plugins = [
   [
@@ -32,7 +33,7 @@ const plugins = [
             },
           }
         : {},
-      ...(!process.env.TEST && os.platform() === 'darwin'
+      ...(!TEST && os.platform() === 'darwin'
         ? {
             dll: {
               include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
@@ -47,7 +48,7 @@ const plugins = [
 
 // 针对 preview.pro.ant.design 的 GA 统计代码
 // 业务上不需要这个
-if (process.env.APP_TYPE === 'site') {
+if (APP_TYPE === 'site') {
   plugins.push([
     'umi-plugin-ga',
     {
@@ -60,7 +61,7 @@ export default {
   // add for transfer to umi
   plugins,
   define: {
-    APP_TYPE: process.env.APP_TYPE || '',
+    APP_TYPE: APP_TYPE || '',
   },
   treeShaking: true,
   targets: {
@@ -75,6 +76,10 @@ export default {
   },
   externals: {
     '@antv/data-set': 'DataSet',
+    // if is production externals react react-dom and bizcharts
+    ...(NODE_ENV === 'production'
+      ? { react: 'React', 'react-dom': 'ReactDOM', bizcharts: 'BizCharts' }
+      : {}),
   },
   // proxy: {
   //   '/server/api/': {

+ 6 - 1
src/pages/document.ejs

@@ -9,7 +9,12 @@
     />
     <title>Ant Design Pro</title>
     <link rel="icon" href="/favicon.png" type="image/x-icon" />
-    <script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.data-set-0.9.6/dist/data-set.min.js"></script>
+    <% if(context.env === 'production') { %>
+    <script src="//gw.alipayobjects.com/os/lib/react/16.8.1/umd/react.production.min.js"></script>
+    <script src="//gw.alipayobjects.com/os/lib/react-dom/16.8.1/umd/react-dom.production.min.js"></script>
+    <script src="//gw.alipayobjects.com/os/lib/bizcharts/3.4.3/umd/BizCharts.min.js"></script>
+    <% }%>
+    <script src="https://gw.alipayobjects.com/os/lib/antv/data-set/0.10.1/dist/data-set.min.js"></script>
   </head>
   <body>
     <noscript>Sorry, we need js to run correctly!</noscript>