| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 | 
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')const path = require('path')const defaultSettings = require('./src/config/index.js')const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPluginconst resolve = dir => path.join(__dirname, dir)// page titleyconst name = defaultSettings.title;// 生产环境,测试和正式const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)const { defineConfig } = require('@vue/cli-service')require('events').EventEmitter.defaultMaxListeners = 0;// externals// const externals = {//   vue: 'Vue',//   'vue-router': 'VueRouter',//   vuex: 'Vuex',//   vant: 'vant',//   axios: 'axios'// }// CDN外链,会插入到index.html中// const cdn = {//   // 开发环境//   dev: {//     css: [],//     js: []//   },//   // 生产环境//   build: {//     css: ['https://cdn.jsdelivr.net/npm/vant@2.4.7/lib/index.css'],//     js: [//       'https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js',//       'https://cdn.jsdelivr.net/npm/vue-router@3.1.5/dist/vue-router.min.js',//       'https://cdn.jsdelivr.net/npm/axios@0.19.2/dist/axios.min.js',//       'https://cdn.jsdelivr.net/npm/vuex@3.1.2/dist/vuex.min.js',//       'https://cdn.jsdelivr.net/npm/vant@2.4.7/lib/index.min.js'//     ]//   }// }module.exports = defineConfig({    publicPath: './', // 署应用包时的基本 URL。 vue-router hash 模式使用  outputDir: 'app', //  生产环境构建文件的目录  assetsDir: 'static', //  outputDir的静态资源(js、css、img、fonts)目录  lintOnSave: !IS_PROD,  productionSourceMap: true, // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。  devServer: {    port: 8181, // 端口    open: false, // 启动后打开浏览器    client: {      overlay: false    },    /*本地开发请求代理*/    proxy: {      //配置跨域      '/luojun': {          target: "http://10.87.10.49:8080",          // ws:true,          changOrigin:true,          pathRewrite:{            '^/luojun':'/'          }      },      // '/jingyuanchao': {      //     target: "http://10.87.10.109:8080",      //     // ws:true,      //     changOrigin:true,      //     pathRewrite:{      //       '^/jingyuanchao':'/'      //     }      // },      '/jingyuanchao': {          target: "http://10.87.11.173:8080",          // ws:true,          changOrigin:true,          pathRewrite:{            '^/jingyuanchao':'/'          }      },      '/luowei': {        target: "http://10.87.10.47:8080",        // ws:true,        changOrigin:true,        pathRewrite:{          '^/luowei':'/'        }      },      '/gaoxiong': {        target: "http://10.87.11.94:8080",        // ws:true,        changOrigin:true,        pathRewrite:{          '^/gaoxiong':'/'        }      },      '/jwx': {        target: "http://10.87.23.50:8080",        // ws:true,        changOrigin:true,        pathRewrite:{          '^/jwx':'/'        }      },      '/zl': {        target: "http://10.87.10.73:8080",        // ws:true,        changOrigin:true,        pathRewrite:{          '^/zl':'/'        }      },      '/online': {        target: "http://47.92.229.224:8080",        // ws:true,        changOrigin:true,        pathRewrite:{          '^/online':'/'        }      },      '/dev': {        target: "http://47.92.229.224:8080",        // target: "http://10.87.23.48:8080",        // ws:true,        changOrigin:true,        pathRewrite:{          '^/dev':'/'        }      },      '/test': {        target: "http://10.87.21.107:8080",        // ws:true,        changOrigin:true,        pathRewrite:{          '^/test':'/'        }      },      '/chao': {        target: "http://10.87.10.34:8080",        // ws:true,        changOrigin:true,        pathRewrite:{          '^/chao':'/'        }      },    }  },  css: {    extract: IS_PROD, // 是否将组件中的 CSS 提取至一个独立的 CSS 文件中 (而不是动态注入到 JavaScript 中的 inline 代码)。    sourceMap: false,    loaderOptions: {      scss: {        // 向全局sass样式传入共享的全局变量, $src可以配置图片cdn前缀        // 详情: https://cli.vuejs.org/guide/css.html#passing-options-to-pre-processor-loaders        additionalData: `          @import "assets/css/mixin.scss";          @import "assets/css/variables.scss";          $cdn: "${defaultSettings.$cdn}";          `      }    }  },  configureWebpack: config => {    config.name = name    // config.plugins= [new NodePolyfillPlugin()]    // 为生产环境修改配置...    // if (IS_PROD) {    //   // externals    //   config.externals = externals    // }  },  chainWebpack: config => {    config.plugins.delete('preload') // TODO: need test    config.plugins.delete('prefetch') // TODO: need test    // 别名 alias    config.resolve.alias      .set('@', resolve('src'))      .set('assets', resolve('src/assets'))      .set('api', resolve('src/api'))      .set('views', resolve('src/views'))      .set('components', resolve('src/components'))    /**     * 添加CDN参数到htmlWebpackPlugin配置中     */    // config.plugin('html').tap(args => {    //   if (IS_PROD) {    //     args[0].cdn = cdn.build    //   } else {    //     args[0].cdn = cdn.dev    //   }    //   return args    //  })    /**     * 设置保留空格     */    config.module      .rule('vue')      .use('vue-loader')      .loader('vue-loader')      .tap(options => {        options.compilerOptions.preserveWhitespace = true        return options      })      .end()    /**     * 打包分析     */    if (IS_PROD) {      config.plugin('webpack-report').use(BundleAnalyzerPlugin, [        {          analyzerMode: 'static'        }      ])    }    config      // https://webpack.js.org/configuration/devtool/#development      .when(!IS_PROD, config => config.devtool('cheap-source-map'))    config.when(IS_PROD, config => {      config.optimization.splitChunks({        chunks: 'all',        cacheGroups: {          // cacheGroups 下可以可以配置多个组,每个组根据test设置条件,符合test条件的模块          commons: {            name: 'chunk-commons',            test: resolve('src/components'),            minChunks: 3, //  被至少用三次以上打包分离            priority: 5, // 优先级            reuseExistingChunk: true // 表示是否使用已有的 chunk,如果为 true 则表示如果当前的 chunk 包含的模块已经被抽取出去了,那么将不会重新生成新的。          },          node_vendors: {            name: 'chunk-libs',            chunks: 'initial', // 只打包初始时依赖的第三方            test: /[\\/]node_modules[\\/]/,            priority: 10          },          vantUI: {            name: 'chunk-vantUI', // 单独将 vantUI 拆包            priority: 20, // 数字大权重到,满足多个 cacheGroups 的条件时候分到权重高的            test: /[\\/]node_modules[\\/]_?vant(.*)/          }        }      })      config.optimization.runtimeChunk('single')    })  }})
 |