angular项目的webpack如何配置gzip压缩?
How to configure gzip compression in webpack of angular project?
Gzip 压缩在 angular 5 项目中不起作用,该项目在 iis 中托管后使用 webpack 3.10.0。我试过的插件是 compression-webpack-plugin@1.0.0 和 brotli-gzip-webpack-plugin.
下面显示的是示例代码,插件包含在生产配置中。
const BrotliGzipPlugin = require('brotli-gzip-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
plugins: [
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.(js|html)$/,
threshold: 10240,
minRatio: 0.8
}),
new BrotliGzipPlugin({
asset: '[path].br[query]',
algorithm: 'brotli',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8
}),
new BrotliGzipPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8
})
]
}
预计加载较小的文件并包含类似于 content-encoding 的内容:gzip 作为响应 headers.
- 为什么在 prod 模式下文件没有替换为 gz 版本?
- 是否有任何 IIS 配置可以让它工作?
这是我构建的样子,它还有 gzip、brotli 文件。
GZIP 压缩通常是您的网络服务器(如 Apache、Nginx 或在您的情况下是 IIS)的任务。
看看这个post:
在 ASP.Net 核心 .
上提供压缩文件时,需要使用 CompressedStaticFiles 中间件
在 Startup.Configure().
中放置 app.UseCompressedStaticFiles();
而不是 app.UseStaticFiles();
如果浏览器支持,这将确保您的应用程序将提供预压缩的 gzip 和 brotli 压缩文件。
参考brotli-gzip-webpack-plugin了解详情。
Gzip 压缩在 angular 5 项目中不起作用,该项目在 iis 中托管后使用 webpack 3.10.0。我试过的插件是 compression-webpack-plugin@1.0.0 和 brotli-gzip-webpack-plugin.
下面显示的是示例代码,插件包含在生产配置中。
const BrotliGzipPlugin = require('brotli-gzip-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
plugins: [
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.(js|html)$/,
threshold: 10240,
minRatio: 0.8
}),
new BrotliGzipPlugin({
asset: '[path].br[query]',
algorithm: 'brotli',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8
}),
new BrotliGzipPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8
})
]
}
预计加载较小的文件并包含类似于 content-encoding 的内容:gzip 作为响应 headers.
- 为什么在 prod 模式下文件没有替换为 gz 版本?
- 是否有任何 IIS 配置可以让它工作?
这是我构建的样子,它还有 gzip、brotli 文件。
GZIP 压缩通常是您的网络服务器(如 Apache、Nginx 或在您的情况下是 IIS)的任务。
看看这个post:
在 ASP.Net 核心 .
上提供压缩文件时,需要使用 CompressedStaticFiles 中间件在 Startup.Configure().
app.UseCompressedStaticFiles();
而不是 app.UseStaticFiles();
如果浏览器支持,这将确保您的应用程序将提供预压缩的 gzip 和 brotli 压缩文件。
参考brotli-gzip-webpack-plugin了解详情。