loulijun2021
2023-03-03 0fe5b8389c7025ce34a05d3920d1d6c169f9fea7
vue.config.js
@@ -1,6 +1,7 @@
'use strict'
const path = require('path')
const defaultSettings = require('./src/settings.js')
const webpack = require('webpack')
function resolve(dir) {
  return path.join(__dirname, dir)
@@ -28,6 +29,19 @@
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: process.env.NODE_ENV === 'development',
  // css: {
  //   loaderOptions: {
  //     css: {},
  //     postcss: {
  //       plugins: [
  //         require('postcss-px2rem')({
  //           remUnit: 192// /设计图宽度/10
  //         })
  //       ]
  //     }
  //   }
  // },
  transpileDependencies: ['screenfull'],
  productionSourceMap: false,
  devServer: {
    port: port,
@@ -38,11 +52,14 @@
    },
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        target: 'http://121.196.36.24:8001', // 请求的第三⽅接⼝地址
        changeOrigin: true, // 请求跨域时,需配置此项
        target: 'http://121.196.36.24:8001', // 请求的第三⽅接⼝地址       本地开发服务器
        // target: 'http://192.168.2.138:8001', // 请求的第三⽅接⼝地址   客户服务器(大岛)
        // target: 'http://192.168.5.176:8001', // 请求的第三⽅接⼝地址   客户服务器(普登)
        changeOrigin: true, // 请求跨域时,需 配置此项
        pathRewrite: { // 路径重写,替换target中的请求地址
          ['^' + process.env.VUE_APP_BASE_API]: '/api/'
        }
        // ws: true;//开启ws, 如果是http代理此处可以不用设置
      }
    }
    // before: require('./mock/mock-server.js')
@@ -55,7 +72,21 @@
      alias: {
        '@': resolve('src')
      }
    }
    },
    plugins: [
      new webpack.ProvidePlugin({
        jQuery: 'jquery',
        $: 'jquery'
      })
    ],
    // module: {
      // rules: [
      //   {
      //     test: /.vue$/,
      //     loader: 'vue-loader'
      //   }
      // ]
    // }
  },
  chainWebpack(config) {
    // it can improve the speed of the first screen, it is recommended to turn on preload
@@ -96,34 +127,34 @@
            .plugin('ScriptExtHtmlWebpackPlugin')
            .after('html')
            .use('script-ext-html-webpack-plugin', [{
            // `runtime` must same as runtimeChunk name. default is `runtime`
              // `runtime` must same as runtimeChunk name. default is `runtime`
              inline: /runtime\..*\.js$/
            }])
            .end()
          config
            .optimization.splitChunks({
              chunks: 'all',
              cacheGroups: {
                libs: {
                  name: 'chunk-libs',
                  test: /[\\/]node_modules[\\/]/,
                  priority: 10,
                  chunks: 'initial' // only package third parties that are initially dependent
                },
                elementUI: {
                  name: 'chunk-elementUI', // split elementUI into a single package
                  priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
                  test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
                },
                commons: {
                  name: 'chunk-commons',
                  test: resolve('src/components'), // can customize your rules
                  minChunks: 3, //  minimum common number
                  priority: 5,
                  reuseExistingChunk: true
                }
            chunks: 'all',
            cacheGroups: {
              libs: {
                name: 'chunk-libs',
                test: /[\\/]node_modules[\\/]/,
                priority: 10,
                chunks: 'initial' // only package third parties that are initially dependent
              },
              elementUI: {
                name: 'chunk-elementUI', // split elementUI into a single package
                priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
                test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
              },
              commons: {
                name: 'chunk-commons',
                test: resolve('src/components'), // can customize your rules
                minChunks: 3, //  minimum common number
                priority: 5,
                reuseExistingChunk: true
              }
            })
            }
          })
          // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
          config.optimization.runtimeChunk('single')
        }