如何在laravel/vue项目中启用文本压缩?

inn6fuwd  于 2023-01-21  发布在  Vue.js
关注(0)|答案(1)|浏览(211)

灯塔显示以下解决方案。
我在我的.htaccess文件中尝试了这个。但是在网络中内容编码不显示。我选择了g.zip压缩

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# for text compression
<IfModule mod_deflate.c>

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

</IfModule>

我在我的.htaccess文件中尝试了这个。但是在网络中内容编码不显示。我在g.zip压缩

中使用了这个

bhmjp9jg

bhmjp9jg1#

对于@vue/cli项目:

  • yarn add -D compression-webpack-plugin(或等效的npm/pnpm
  • vue.config.js中(如果没有,请在root中创建):
const CompressionPlugin = require("compression-webpack-plugin")
module.exports = {
  configureWebpack: {
    plugins: [
      new CompressionPlugin(),
      /* other plugins */
    ]
  }
}

或者,您可以使用现有的vue-cli plugin。阅读安装和配置文档。
对于vite项目:

  • yarn add -D vite-plugin-compression(或npm/pnpm等效产品)
  • vite.config.js中(如果没有,请在root中创建):
import viteCompression from 'vite-plugin-compression'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    viteCompression(),
    /* other plugins */
  ],
})

相关问题