Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular4 build - gzip missing

When I run ng build -prod --aot only .js files are being produced.

output:

chunk    {0} polyfills.a2079361c5ff6d4e321e.bundle.js (polyfills) 285 kB {5} [initial] [rendered]
chunk    {1} main.d19edcafc399a0af8c0b.bundle.js (main) 2.33 MB {4} [initial] [rendered]
chunk    {2} scripts.22988bec4cd6ce344e9f.bundle.js (scripts) 973 kB {5} [initial] [rendered]
chunk    {3} styles.99705fb1bf9015185149.bundle.css (styles) 705 bytes {5} [initial] [rendered]
chunk    {4} vendor.377addf0a4997a085d42.bundle.js (vendor) 4.71 MB [initial] [rendered]
chunk    {5} inline.911ff25c95430bbf496e.bundle.js (inline) 0 bytes [entry] [rendered]

My questions are:

  1. What happened to the .gz files?
  2. How do I serve gzip files from express?
like image 688
Moshe Avatar asked Mar 24 '17 17:03

Moshe


1 Answers

  1. As stated on 1.0.0-beta.32 (2017-02-17)'s BREAKING CHANGES List, since 1.0.0-beta.32

    @angular/cli: compressed output (.gz) is no longer generated on production builds.

    also, since 1.0.0-beta.28,

    --aot defaults to true in --prod

    so, you do not need to add --aot flag when running ng build -prod

    in order to get gz files back you can eject your app by running ng eject which will expose your webpack.config.js file, where you can use COMPRESSION WEBPACK PLUGIN:

    const CompressionPlugin = require("compression-webpack-plugin"); 
    . . . 
    new CompressionPlugin({})
    

    (to 'uneject' your app again see my answer)

  2. In order to serve gz files from express you can use Node JS compression middleware:

    var compression = require('compression')
    var express = require('express')
    
    var app = express()
    
    // compress all responses
    app.use(compression())
    
like image 50
Andriy Avatar answered Oct 16 '22 04:10

Andriy