Files
energy_app/vue.config.js
jiangyinzhi d883b51b0d 修改
2025-12-25 09:28:02 +08:00

185 lines
6.2 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @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 = 9527 // 端口
module.exports = {
assetsDir: 'asset',
// outputDir: ('1006028-' + pkgInfo.version), //生产包
outputDir: 'dist', //测试环境
lintOnSave: false,
parallel: 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,
hot: true,
open: true,
proxy: {
"/admin": {
// target: "http://121.28.84.19:9004",
target: "http://172.29.106.250:19012",
changeOrigin: true,
pathRewrite: {
"^/admin": "",
},
}, "/energy-effcicency-net-service": {
// target: "http://121.28.84.19:9004",
target: "http://172.29.106.250:19012",
changeOrigin: true,
pathRewrite: {
"^/energy-effcicency-net-service": "",
},
},
// [process.env.VUE_APP_BASE_API]: {
// target: process.env.VUE_APP_SERVER_Url,
// changeOrigin: true,
// secure: false,
// 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
}