Angular4 build - gzip缺失

Mos*_*she 10 angular-cli angular

当我ng build -prod --aot只运行.js文件时.

输出:

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]
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. .gz文件怎么了?
  2. 如何从express提供gzip文件?

And*_*riy 9

  1. 正如1.0.0-beta.32(2017-02-17)的突破性变化列表所述,自1.0.0-beta.32

    @ angular/cli:生产版本不再生成压缩输出(.gz).

    此外,自1.0.0-beta.28,

    - 在--prod中默认为true

    所以,你不需要--aot在运行时添加标志ng build -prod

    为了获取gz文件,你可以通过运行弹出你的应用程序,ng eject这将暴露你的webpack.config.js文件,你可以在其中使用COMPRESSION WEBPACK PLUGIN:

    const CompressionPlugin = require("compression-webpack-plugin"); 
    . . . 
    new CompressionPlugin({})
    
    Run Code Online (Sandbox Code Playgroud)

    ('再次'取消'你的应用程序看到我的答案)

  2. 为了从express提供gz文件,你可以使用Node JS压缩中间件:

    var compression = require('compression')
    var express = require('express')
    
    var app = express()
    
    // compress all responses
    app.use(compression())
    
    Run Code Online (Sandbox Code Playgroud)