/* * @Author: your name * @Date: 2021-04-21 17:15:14 * @LastEditTime: 2022-02-16 10:44:15 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \sxt_web_app\vue.config.js */ // const CompressionWebpackPlugin = require('compression-webpack-plugin'); const productionGzipExtensions = ['js', 'css']; const isProduction = process.env.NODE_ENV === 'production'; const path = require('path') const resolve = dir => path.join(__dirname, dir) const webpack = require('webpack') // eslint-disable-next-line no-unused-vars const pkgInfo = require('./package.json') const port = 6600 // 端口 module.exports = { assetsDir: 'asset', // outputDir: ('1006028-' + pkgInfo.version), //生产包 outputDir: 'dist', //测试环境 lintOnSave: false, publicPath: '', chainWebpack: config => { config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin), config.plugins.delete('preload') config.plugins.delete('prefetch') // config.module.rule("js").include.add(resolve("./node_modules/resize-detector/esm/index.js","./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./node_modules/cube-ui/src/components/loading/loading.vue?vue&type=script&lang=js&")).add(resolve("src")) config.resolve.alias .set('@', resolve('src')) .set('_c', resolve('src/components')) config.optimization.splitChunks({ chunks: 'all', //async异步代码分割 initial同步代码分割 all同步异步分割都开启 // minSize: 10000,//字节 引入的文件大于30kb才进行分割 // minChunks: 2, //模块至少使用次数 // maxAsyncRequests: 25,    //同时加载的模块数量最多是5个,只分割出同时引入的前5个文件 // maxInitialRequests: 30,  //首页加载的时候引入的文件最多3个 automaticNameDelimiter: '-', //缓存组和生成文件名称之间的连接符 // name: true,//缓存组里面的filename生效,覆盖默认命名 cacheGroups: { vue: { name: 'vue', test: /[\\/]node_modules[\\/]vue[\\/]/, priority: -10 }, yakuza1: { name: 'yakuza1', test: /[\\/]node_modules[\\/]yakuza1(.*)/, priority: -10 }, jspdf: { name: 'jspdf', test: /[\\/]node_modules[\\/]_?jspdf(.*)/, priority: -10 }, html2canvas: { name: 'html2canvas', test: /[\\/]node_modules[\\/]_?html2canvas(.*)/, priority: -10 }, vuex: { name: 'vuex', test: /[\\/]node_modules[\\/]vuex[\\/]/, priority: -10 }, 'vue-router': { name: 'vue-router', test: /[\\/]node_modules[\\/]vue-router[\\/]/, priority: -10 }, vantUI: { name: 'chunk-vant', test: /[\\/]node_modules[\\/]_?vant(.*)/, priority: -10 }, 'libs-common-utils': { name: 'libs-common-utils', test: /[\\/]node_modules[\\/]libs-common-utils[\\/]/, priority: -10 }, // vendors: { // test: /[\\/]node_modules[\\/]/, // priority: -20 // }, //公用模块抽离 common: { chunks: 'initial', minSize: 0, //大于0个字节 minChunks: 2 //抽离公共代码时,这个代码块最小被引用的次数 }, //第三方库抽离 vendor: { priority: 1, //权重 test: /node_modules/, chunks: 'initial', minSize: 0, //大于0个字节 minChunks: 2 //在分割之前,这个代码块最小应该被引用的次数 } } }) }, css: { loaderOptions: { css: {}, postcss: { plugins: [ // function (css, result) { // var oldCssText = css.toString(); // var px2remIns = new Px2rem(options); // var newCssText = px2remIns.generateRem(oldCssText); // var newCssObj = postcss.parse(newCssText); // result.root = newCssObj; // } require('postcss-px2rem')({ remUnit: 37.5 }) ] }, stylus: { 'resolve url': true, import: ['./src/theme'] } } }, pluginOptions: { 'cube-ui': { postCompile: true, theme: true } }, devServer: { host: '0.0.0.0', port: port, open: true, proxy: { [process.env.VUE_APP_BASE_API]: { target: `http://172.29.69.38:28083`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' } } }, disableHostCheck: true }, configureWebpack: config => { // if (process.env.NODE_ENV === 'production') { // // 为生产环境修改配置... config.devtool = '#cheap-module-eval-source-mapp' // // process.env.appCode = 'JSINTXCGK' // // process.env.appServer = 'xcgkAppServer' // } else { // // 为开发环境修改配置... // } config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)) // if (isProduction) { // config.plugins.push(new CompressionWebpackPlugin({ // algorithm: 'gzip', // test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), // threshold: 10240, // minRatio: 0.8, // deleteOriginalAssets: false // 删除原文件 // })) // } }, // runtimeCompiler: true, // publicPath: '/', // 设置打包文件相对路径 // 打包时不生成.mapw文件,减少打包体积,提升速度 productionSourceMap: false }