czrm/vue.config.js
2025-03-29 11:39:46 +08:00

160 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict'
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const webpack = require("webpack");
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
lintOnSave: process.env.NODE_ENV !== "production",
productionSourceMap: false, // 生产环境关闭 source map
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
css: {
loaderOptions: {
less: {
// lessOptions: {
// If you are using less-loader@5 please spread the lessOptions to options directly
modifyVars: {
"primary-color": "#1890ff",
"link-color": "#1890ff",
"border-radius-base": "2px",
},
javascriptEnabled: true,
// },
},
},
},
configureWebpack: (config) => {
if (process.env.NODE_ENV === "production") {
// 打包分析工具
config.plugins.push(new BundleAnalyzerPlugin());
// 取消 console.log
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
}else{
// config.devtool = "source-map";
}
},
chainWebpack: (config) => {
config
.plugin("ignore")
// 忽略/moment/locale下的所有文件
.use(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));
// 按需加载icon
config.resolve.alias
.set('@ant-design/icons/lib/dist$',resolve("src/index/utils/lazy/icons.js"))
// 拆分chunk
config.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
common: {
name: 'chunk-common', // 打包后的文件名
chunks: 'initial', // 非动态模块打包进该vendor,动态模块优化打包
minChunks: 2,
maxInitialRequests: 5,
minSize: 0,
priority: 1,
reuseExistingChunk: true
},
libs: {
name: 'chunk-vendors',
test: /[\\/]node_modules[\\/]/,
chunks: 'initial',
priority: 2,
reuseExistingChunk: true,
},
antDesignVue: {
name: 'chunk-antDesignVue', // 单独将 antdesignvue 拆包
test: /[\\/]node_modules[\\/]ant-design-vue[\\/]/,
priority: 3,
reuseExistingChunk: true,
},
// echarts: {
// name: 'chunk-echarts',
// test: /[\\/]node_modules[\\/]echarts[\\/]|[\\/]node_modules[\\/]zrender[\\/]/,
// priority: 4,
// reuseExistingChunk: true,
// },
// default: {
// minChunks: 2,
// priority: -20,
// reuseExistingChunk: true
// }
},
})
// 图片不转base64, 因为后端设置了csp策略
config.module
.rule('images')
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, { limit: -1 }))
config.plugins.delete('prefetch') // 去掉空闲加载
// 生产环境开启js\css压缩
if (process.env.NODE_ENV === 'production') {
config.plugin('compressionPlugin').use(
new CompressionPlugin({
test: /\.(js|css|less|html)$/, // 匹配文件名
threshold: 10240, // 对超过10k的数据压缩
deleteOriginalAssets: false, // 不删除源文件
})
)
}
},
devServer: {
port: 3005,
proxy: {
"^/proxy": {
// 南航UAT
// target: "https://csair.joosure.com",
// 阿里云
// target: "http://47.119.167.172",
// yapi
target: "https://yapi.081024.xyz/mock/11",
// 需求映射规则
// target: "http://134.175.125.24",
// 志龙电脑
// target: "http://192.168.20.168:9004",
// 林伟电脑
// target: "http://192.168.20.79:9005",
changeOrigin: true,
pathRewrite: {
'/proxy':''
}
},
},
},
pages: {
index: {
entry: 'src/index/main.js',
template: 'public/index.html',
filename: 'index.html',
title: '资源管理',
chunks: ['chunk-vendors', 'chunk-common','chunk-antDesignVue', 'index']
},
storyMountPoint: {
entry: 'src/storyMountPoint/main.js',
template: 'public/storyMountPoint.html',
filename: 'storyMountPoint.html',
title: '指定团队和技改项目',
chunks: ['chunk-vendors','chunk-common','chunk-antDesignVue', 'storyMountPoint']
},
}
};