Vue 打包過大處理,gzip_static 提高訪問效率

提高前端訪問效率

參考網址

下載地址

壓縮包在文末

以 jeecg-boot 2.1.1爲測試腳步

1.下載nginx tar.gz

tar -zxvf …

./configure --prefix=/etc/nginx --with-http_gzip_static_module --with-http_gunzip_module

make 

make install

處理 /etc/nginx/conf/nginx.conf 處理server

 server {

        listen       80;

        server_name  訪問域名;

        location / {

          root  /前端地址;

        index /index.html;

        try_files $uri $uri/ /index.html;

        gzip_static on; #靜態壓縮

        }

    }

2。vue 本地打包

本地安裝 CompressionWebpackPlugin 插件 

處理 vue confg js 

修改webpack 配置 

//生產環境取消 console.log

if (process.env.NODE_ENV === 'production') {

  config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true

  config.plugins.push(

    new CompressionWebpackPlugin({

  // 正在匹配需要壓縮的文件後綴

            test: /.(js|css|svg|woff|ttf|json|html)$/,

  // 大於10kb的會壓縮

            threshold: 10240

  // 其餘配置查看compression-webpack-plugin

          })

  )

重啓即可

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章