gzip压缩,对应Nginx也要设置

'use strict'
const path = require('path')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css', 'svg', 'json', 'txt']
function resolve (dir) {
  return path.join(__dirname, dir)
}


const port = process.env.port || process.env.npm_config_port || 8081 // 端口

// vue.config.js 配置说明
//官方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/。
  publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
  outputDir: 'dist',
  // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  assetsDir: 'static',
  // 是否开启eslint保存检测,有效值:ture | false | 'error'
  lintOnSave: process.env.NODE_ENV === 'development',
  // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  productionSourceMap: false,
  // webpack-dev-server 相关配置
  devServer: {
    host: '0.0.0.0',
    port: port,
    open: true,
    proxy: {
      // detail: https://cli.vuejs.org/config/#devserver-proxy
      [process.env.VUE_APP_BASE_API]: {
        // target: `http://127.0.0.1:8080`,
        target: `http://10.4.120.109:8090`,
        // target: `http://10.4.114.116:8080`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      },
      [process.env.VUE_APP_BASE_API + '/seal/websocket']: {
        // target: `http://10.4.120.109:8090`,
        target: `ws://10.4.127.97:8080`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API + '/seal/websocket']: ''
        }
      }
    },
    disableHostCheck: true
  },
  configureWebpack: {
    name: '综合信息集成平台', // 网页标题
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  },
  chainWebpack (config) {
    config.plugins.delete('preload') // TODO: need test
    config.plugins.delete('prefetch') // TODO: need test
    if (process.env.NODE_ENV === 'production') {
      // 压缩
      config.plugin('CompressionWebpackPlugin').use(new CompressionWebpackPlugin({
        // filename: '[path].gz[query]',
        algorithm: 'gzip',
        test: new RegExp(
          '\\.(' + productionGzipExtensions.join('|') + ')$'
        ),
        threshold: 10240, // 只有大小大于该值的资源会被处理 10240
        minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
        deleteOriginalAssets: false // 删除原文件
      }))
    }
    // set svg-sprite-loader
    config.module
      .rule('svg')
      .exclude.add(resolve('src/assets/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/assets/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()

    config
      .when(process.env.NODE_ENV !== 'development',
        config => {
          config
            .plugin('ScriptExtHtmlWebpackPlugin')
            .after('html')
            .use('script-ext-html-webpack-plugin', [{
              // `runtime` must same as runtimeChunk name. default is `runtime`
              inline: /runtime\..*\.js$/
            }])
            .end()
          config
            .optimization.splitChunks({
              chunks: 'all',
              cacheGroups: {
                libs: {
                  name: 'chunk-libs',
                  test: /[\\/]node_modules[\\/]/,
                  priority: 10,
                  chunks: 'initial' // only package third parties that are initially dependent
                },
                elementUI: {
                  name: 'chunk-elementUI', // split elementUI into a single package
                  priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
                  test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
                },
                commons: {
                  name: 'chunk-commons',
                  test: resolve('src/components'), // can customize your rules
                  minChunks: 3, //  minimum common number
                  priority: 5,
                  reuseExistingChunk: true
                }
              }
            })
          config.optimization.runtimeChunk('single'),
          {
            from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
            to: './' //到根目录下
          }
        }
      )
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
):"; cin >> workers[index].gender; break; case '4': cout << "请输入新的工资:"; cin >> workers[index].salary; break; default: cout << "无效的操作,请重新选择!是的,当你使用 Vue CLI 生成的项目进行打包后,需要将打包后的文件部署到 Web " << endl; break; } cout << "修改成功!" << endl; } // 修改所有职工信息 void服务器上才能访问。常见的 Web 服务器有 Nginx、Apache、IIS 等,其中 Nginx 是 modifyAll() { cout << "请输入要修改的职工编号:"; int id; cin >> id; int index一个轻量级的高性能 Web 服务器,也是一个常见的选择。 下面是将 Vue 项目部署 = -1; for (int i = 0; i < workerCount; i++) { if (workers[i].id ==到 Nginx 上的一些常见配置: 1. 首先,在 Nginx 的配置文件中添加一个 server 块, id) { index = i; break; } } if (index == -1) { cout << "未指定监听的端口和域名(如果有): ``` server { listen 80; server_name example.com; 找到该职工信息!" << endl; return; } cout << "请输入新的职工编号:"; } ``` 2. 在 server 块中添加一个 location 块,指定请求的 URL 和对应的文件路径: ``` location int newId; cin >> newId; for (int i = 0; i < workerCount; i++) { if / { root /path/to/your/dist; index index.html; try_files $uri $uri/ /index.html; } (i != index && workers[i].id == newId) { cout << "职工编号已存在,请重新输入!" <<``` 上面的配置中,`/path/to/your/dist` 是你打包后的文件夹路径,`index.html endl; return; } } workers[index].id = newId; cout << "请输入新的姓名:"; ` 是默认的入口文件名。`try_files` 用于指定如果请求的文件不存在时,应该返回哪 cin >> workers[index].name; cout << "请输入新的年龄:"; cin >> workers[index].age; cout个文件。 3. 可选的配置项包括缓存、gzip 压缩等,下面是一个完整的示例 << "请输入新的性别(M/F):"; cin >> workers[index].gender; cout << "请输入新的工: ``` server { listen 80; server_name example.com; root /path/to/your/dist; index index.html资:"; cin >> workers[index].salary; cout << "修改成功!" << endl; } // 按编号升序排序; # 缓存配置 add_header Cache-Control no-cache; expires 0; # gzip 压缩 gzip on void sortByIdAsc() { for (int i = 0; i < workerCount - 1; i++) { for (int j = 0; j < workerCount - i - 1; j++) { if (workers[j].id > workers; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; location / { [j + 1].id) { Worker temp = workers[j]; workers[j] = workers[j + 1]; workers try_files $uri $uri/ /index.html; } } ``` 以上是一个基本的 Vue 项目在 Nginx 上的配置,你可以根据自己的需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值