cuiyalong 1 год назад
Родитель
Сommit
980a67d360
2 измененных файлов с 64 добавлено и 1 удалено
  1. 9 0
      jypoints-pc/public/index.html
  2. 55 1
      jypoints-pc/vue.config.js

+ 9 - 0
jypoints-pc/public/index.html

@@ -30,6 +30,15 @@
 
 
     <script ignore src="http://localhost/js/coupon/coupon.js"></script>
     <script ignore src="http://localhost/js/coupon/coupon.js"></script>
     <% } %>
     <% } %>
+
+    <!-- 使用CDN的CSS文件 -->
+    <% for (var i in htmlWebpackPlugin.options.cdn && htmlWebpackPlugin.options.cdn.css) { %>
+    <link rel="stylesheet" href="<%= htmlWebpackPlugin.options.cdn.css[i] %>" />
+    <% } %>
+    <!-- 使用CDN的JS文件 -->
+    <% for (var i in htmlWebpackPlugin.options.cdn && htmlWebpackPlugin.options.cdn.js) { %>
+    <script type="text/javascript" src="<%= htmlWebpackPlugin.options.cdn.js[i] %>"></script>
+    <% } %>
   </head>
   </head>
   <body>
   <body>
     <noscript>
     <noscript>

+ 55 - 1
jypoints-pc/vue.config.js

@@ -1,6 +1,27 @@
 const packageName = require('./package.json').name
 const packageName = require('./package.json').name
 const webpack = require('webpack')
 const webpack = require('webpack')
 
 
+const cdn = {
+  css: [
+    // '//unpkg.com/element-ui@2.10.1/lib/theme-chalk/index.css'
+  ],
+  js: [
+    '//cdn-common.jianyu360.com/cdn/lib/vue/2.6.11/vue.min.js',
+    '//cdn-common.jianyu360.com/cdn/lib/vue-router/3.5.4/vue-router.min.js',
+    '//cdn-common.jianyu360.com/cdn/lib/vuex/3.4.0/vuex.min.js',
+    '//cdn-common.jianyu360.com/cdn/lib/axios/0.19.2/axios.min.js',
+    '//cdn-common.jianyu360.com/cdn/lib/lodash/4.17.21/lodash.min.js',
+  ]
+}
+
+const external = {
+  vue: 'Vue',
+  'vue-router': 'VueRouter',
+  vuex: 'Vuex',
+  axios: 'axios',
+  lodash: '_',
+}
+
 module.exports = {
 module.exports = {
   parallel: false,
   parallel: false,
   productionSourceMap: false,
   productionSourceMap: false,
@@ -12,6 +33,10 @@ module.exports = {
     port: '8080',
     port: '8080',
     disableHostCheck: true,
     disableHostCheck: true,
     proxy: {
     proxy: {
+      '^/common-module': {
+        target: 'https://jybx2-webtest.jydev.jianyu360.com/',
+        changeOrigin: true,
+      },
       '^/jyintegral': {
       '^/jyintegral': {
         target: 'https://jybx2-webtest.jydev.jianyu360.com/',
         target: 'https://jybx2-webtest.jydev.jianyu360.com/',
         changeOrigin: true,
         changeOrigin: true,
@@ -33,6 +58,18 @@ module.exports = {
         pathRewrite: {
         pathRewrite: {
           '^/jypay': '/jypay'
           '^/jypay': '/jypay'
         }
         }
+      },
+      '^/jyapi': {
+        target: 'https://jybx2-webtest.jydev.jianyu360.com',
+        changeOrigin: true
+      },
+      '^/jyintegral': {
+        target: 'https://jybx2-webtest.jydev.jianyu360.com',
+        changeOrigin: true
+      },
+      '^/jyActivity': {
+        target: 'https://jybx2-webtest.jydev.jianyu360.com',
+        changeOrigin: true
       }
       }
     }
     }
   },
   },
@@ -44,7 +81,24 @@ module.exports = {
     }
     }
   },
   },
   chainWebpack: config => {
   chainWebpack: config => {
-    if (!process.env.VUE_APP_ALONE) {
+    if (process.env.NODE_ENV === 'production') {
+      // 生产环境配置
+      config.externals(external)
+      config.plugin('html').tap(args => {
+        // html中添加cdn
+        args[0].cdn = cdn
+        return args
+      })
+
+      config.optimization.minimize(true)
+        .minimizer('terser')
+        // .tap(args => {
+        //   const { terserOptions } = args[0]
+        //   terserOptions.compress.drop_console = true
+        //   terserOptions.compress.drop_debugger = true
+        //   return args
+        // })
+    } else {
       config.devServer.set('inline', false)
       config.devServer.set('inline', false)
       config.devServer.set('hot', true)
       config.devServer.set('hot', true)
     }
     }