当前位置: 首页 > news >正文

vue 打包设置

1、vue webpack配置

filename: '[path][base].gz',// 设置成这样就行了

const { defineConfig } = require('@vue/cli-service')const debug = process.env.NODE_ENV !== 'production'const CompressionWebpackPlugin = require('compression-webpack-plugin')const TerserPlugin = require("terser-webpack-plugin");
const productionGzipExtensions = ['js', 'css'];module.exports = defineConfig({transpileDependencies: true,})
module.exports = {publicPath: "./",outputDir: `dist/prod`,lintOnSave: false,//是否开启eslint保存检测 ,它的有效值为 true || false || 'error'\devServer: {open: true, //配置自动启动浏览器// host: "192.168.10.18",https: false,// hotOnly: false, //热更新port: 7878,proxy: {},client: {overlay: false,},},// configureWebpack: {//   resolve: {//     alias: {//       '@': path.resolve(__dirname, 'src')//     }//   }// },// chainWebpack: (config) => {//   config.resolve.alias//     .set('@', resolve('src'))//     .set('assets', resolve('src/assets'));// },// css: {//   loaderOptions: {//     postcss: {//       plugins: [//         require("postcss-px2rem-exclude")({//           remUnit: 192, //1920//           // exclude: /node_modules|folder_name/i//         }),//       ],//     },//   },// },productionSourceMap: false,configureWebpack: config => {if (debug) { // 开发环境配置config.devtool = 'source-map'}else{// 开启分离jsconfig.optimization = {runtimeChunk: 'single',splitChunks: {chunks: 'all',  maxInitialRequests: Infinity,minSize: 20000,cacheGroups: {vendor: {test: /[\\/]node_modules[\\/]/, // 提取 node_modules 中的库name: 'vendors',                // 提取到 vendors.jschunks: 'all',// priority: -10,// name (module) {//   const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]//   return `npm.${packageName.replace('@', '')}`// }},},},minimize: true,minimizer: [new TerserPlugin({extractComments: false,//不将注释提取到单独的文件中terserOptions: {compress: {// 移除 warning,console,debugger等warnings:false, drop_console: true,drop_debugger: true,pure_funcs: ['console.log'] // 移除console},output: {// 去掉注释内容comments: false,}}})]};config.plugins.push(new CompressionWebpackPlugin({// filename: '[path].gz[query]',filename: '[path][base].gz',algorithm: 'gzip',test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),threshold: 10240,minRatio: 0.8,}))}},configureWebpack:{module: {rules: [{test: /\.(jpg|png|gif)$/,use: [{loader: 'image-webpack-loader',options: {mozjpeg: {progressive: true,quality: 65},optipng: {enabled: false},pngquant: {quality: [0.65, 0.90],speed: 4},gifsicle: {interlaced: false},webp: {quality: 75}}}]},],},}}

2、nginx 配置访问gz

http {gzip_static on;          # 启用预压缩文件查找brotli_static on;        # 启用 Brotli 预压缩文件(需安装 ngx_brotli 模块)# 若未找到预压缩文件,动态压缩gzip on;gzip_types text/plain text/css application/json application/javascript text/xml;
}

http://www.xdnf.cn/news/184969.html

相关文章:

  • DFPatternFunctor遍历计算图
  • 【博客系统】博客系统第一弹:博客系统项目配置、MyBatis-Plus 实现 Mapper 接口、处理项目公共模块:统一返回结果、统一异常处理
  • 关于华为高斯数据库出现Invalid or unsupported by client SCRAM mechanisms定位解决的过程
  • -信息革命-
  • OpenManus云端部署及经典案例应用
  • 心磁图技术突破传统局限!心血管疾病早筛迈入“三零“新时代
  • TV launcher官方下载-tv launcher汉化版-tv桌面启动器极简下载
  • c++17 对于临时对象作为右值的优化
  • MRI学习笔记-conjunction analysis
  • Linux——线程(2)线程互斥(锁)
  • 机器学习 | 基于回归模型的交通需求预测案例分析及代码示例
  • 日本IT|UIUX主要的工作都是哪些?及职业前景
  • 【每日随笔】文化属性 ② ( 高维度信息处理 | 强者思维形成 | 认知重构 | 资源捕获 | 进化路径 )
  • LangChain构建大模型应用之RAG
  • 使用ROS实现多机通讯
  • 线上查询车辆出险记录:快速掌握事故情况!
  • 大模型API密钥的环境变量配置(大模型API KEY管理)(将密钥存储在环境变量)(python-dotenv)(密钥管理)
  • 数据结构(七)---链式栈
  • AI看论文自动生成代码库:Paper2Code如何革新科研复现?
  • 函数式链表:Python编程的非常规 “链” 接
  • QT6 源(53)篇三:存储 c 语言字符串的类 QByteArray 的使用举例,
  • 移除生产环境所有console.log
  • 给视频自动打字幕:从Humanoid-X、UH-1到首个人形VLA Humanoid-VLA:迈向整合第一人称视角的通用人形控制
  • 基于STM32、HAL库的AD7616BSTZ模数转换器ADC驱动程序设计
  • Linux操作系统学习---进程地址空间
  • 【LaTex】8.1 文档类与层级
  • 前端权限管理
  • 小刚说C语言刷题——1320时钟旋转
  • 生成式人工智能认证(GAI认证)要学哪些知识?
  • google chrome 中 fcitx5 候选框不跟随光标