Angular4构建-缺少gzip [英] Angular4 build - gzip missing
问题描述
当我运行ng build -prod --aot
时,仅生成.js文件.
When I run ng build -prod --aot
only .js files are being produced.
输出:
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]
我的问题是:
- .gz文件怎么了?
- 如何从express提供gzip文件?
推荐答案
-
如 1.0所述.0-beta.32(2017-02-17)的BREAKING CHANGES列表, 自1.0.0-beta.32
As stated on 1.0.0-beta.32 (2017-02-17)'s BREAKING CHANGES List, since 1.0.0-beta.32
@ angular/cli:在生产版本中不再生成压缩输出(.gz).
@angular/cli: compressed output (.gz) is no longer generated on production builds.
,因为 1.0.0- beta.28 ,
-aot在--prod中默认为true
--aot defaults to true in --prod
因此,运行ng build
-prod
so, you do not need to add --aot
flag when running ng build
-prod
为了取回gz文件,您可以通过运行ng
eject
弹出您的应用程序,这将公开您的 webpack.config.js 文件,您可以在其中
可以使用 压缩网络插件 :
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({})
(再次取消拒绝"您的应用程序,请参阅我的 answer )
(to 'uneject' your app again see my answer)
为了通过express提供gz文件,您可以使用 节点JS 压缩中间件 :
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())
这篇关于Angular4构建-缺少gzip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!