diff --git a/ruoyi-ui/vue.config.js b/ruoyi-ui/vue.config.js index cf31605..18b50a8 100644 --- a/ruoyi-ui/vue.config.js +++ b/ruoyi-ui/vue.config.js @@ -1,6 +1,5 @@ 'use strict' const path = require('path') - function resolve(dir) { return path.join(__dirname, dir) } @@ -15,6 +14,7 @@ const port = process.env.port || process.env.npm_config_port || 80 // 端口 //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions // 这里只列一部分,具体配置参考文档 module.exports = { + // 部署生产环境和开发环境下的URL。 // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上 // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。 @@ -53,24 +53,41 @@ module.exports = { } } }, - configureWebpack: { - name: name, - resolve: { + configureWebpack: (config) => { + // 设置名称(如果需要) + config.name = name; + + // 设置别名 + config.resolve = { + ...config.resolve, alias: { + ...config.resolve.alias, '@': resolve('src') } - }, - plugins: [ - // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件 + }; + + // 初始化插件数组(保留原有插件) + const plugins = [...config.plugins]; + + // 移除 CSS 压缩插件(Vue CLI 4 使用的) + const filteredPlugins = plugins.filter(plugin => { + return plugin.constructor.name !== 'OptimizeCssnanoPlugin'; + }); + + // 添加你自己的插件(如 CompressionPlugin) + filteredPlugins.push( new CompressionPlugin({ - cache: false, // 不启用文件缓存 - test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i, // 压缩文件格式 - filename: '[path][base].gz[query]', // 压缩后的文件名 - algorithm: 'gzip', // 使用gzip压缩 - minRatio: 0.8, // 压缩比例,小于 80% 的文件不会被压缩 - deleteOriginalAssets: false // 压缩后删除原文件 + cache: false, + test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i, + filename: '[path][base].gz[query]', + algorithm: 'gzip', + minRatio: 0.8, + deleteOriginalAssets: false }) - ], + ); + + // 更新插件列表 + config.plugins = filteredPlugins; }, chainWebpack(config) { config.plugins.delete('preload') // TODO: need test