Angular4 构建 - 缺少 gzip [英] Angular4 build - gzip missing

查看:27
本文介绍了Angular4 构建 - 缺少 gzip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 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]

我的问题是:

  1. .gz 文件发生了什么变化?
  2. 如何从 express 提供 gzip 文件?

推荐答案

  1. 1.0 所述.0-beta.32 (2017-02-17) 的重大变化列表,自 1.0.0-beta.32

  1. 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 时不需要添加 --aot 标志-prod

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

为了取回 gz 文件,您可以通过运行 ng 来弹出您的应用程序弹出 它将暴露您的 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({})

(要再次取消"您的应用程序,请参阅我的 回答)

(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆