c# - 我如何将 gzip 用于我的 Angular 项目?

标签 c# angular asp.net-core .net-core asp.net-core-mvc

我读了一些关于减小 Angular 项目大小的文章,在这些文章中我找到了一些解决方案,但其中一个对我来说是晦涩难懂的,那是 gzip 压缩,我的问题是如何在我的应用程序中使用 gzip?

如果对您有帮助,我正在使用 asp.net core 作为我的后端技术。

最佳答案

首先需要安装这两个开发依赖

 "gulp": "^4.0.0",
"gulp-gzip": "^1.4.2",

在你的 package.json 中创建一个 postbuild 脚本

"postbuild": "gulp compress",

在package.json文件的同级创建一个gulpfile.js文件,代码如下

var gulp = require('gulp');
var gzip = require('gulp-gzip');

gulp.task('compress', function() {
    return new Promise(function(resolve, reject) {
        resolve(gulp.src(['./dist/**/*.*'])
        .pipe(gzip())
        .pipe(gulp.dest('./dist')));

    })
});

无论何时构建项目,此构建后命令都会在构建后压缩文件。

关于c# - 我如何将 gzip 用于我的 Angular 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56374487/

相关文章:

c# - 将消息传递给Caliburn Micro中的静态类

c# - 与 VBA 相比,VSTO 性能较慢

C# : Convert datetime from string with different format

angular - 根据条件使用 routerlink 或 href

c# - 在 ASP.NET Core Identity UI 中更改路由?

C# ToString继承

angular - 有没有办法查看 Angular 的 webpack 配置?

Angular 2 : How to write a for loop, 不是 foreach 循环

c# - .NET CORE Razor Pages Ajax 调用 C# 方法

c# - 以英语以外的特定语言获取 ASP.NET Core 模型错误