Hamid
Hamid

Reputation: 908

How can I use gzip for my angular project?

I read some article about decreasing angular project size, in those articles I founded some solution but one of them was Obscure for me and that was gzipped compression, my question is how I can use gzip for my application?

If it helps you, I'm using asp.net core as my back-end technology.

Upvotes: 2

Views: 2135

Answers (2)

Dan Patil
Dan Patil

Reputation: 801

First, you need to install these two dev dependencies

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

Create a postbuild script in your package.json

"postbuild": "gulp compress",

Create a gulpfile.js file at the same level of package.json file with the following code

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')));

    })
});

Whenever you build your project this postbuild command will compress the files for after the build.

Upvotes: 5

Tony
Tony

Reputation: 20092

You can use gzip-all

I'm currently using this version

"gzip-all": "^1.0.0"

So my build command will be

ng build --prod && gzip-all \"dist/*.*\"

So gzip-all will gzip every file in dist folder

Upvotes: 1

Related Questions