Angular ng build --target=production 给出错误 [英] Angular ng build --target=production giving errors

查看:19
本文介绍了Angular ng build --target=production 给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Angular-CLI 创建了一个新的 Angular 项目.

I have a created a new Angular Project using Angular-CLI.

我使用的版本是:

Angular-Cli:1.0.2

Angular-Cli: 1.0.2

角度:4.0.0.

我在其中添加了很多代码,但是现在,当我使用以下命令构建我的项目时,我遇到了一堆错误

I have added a lot of code in it but now, when I build my project using below command I get bunch of errors

ng build --target=production --env=staging

错误:

/src/app/views/signup/signup.component.html (21,86):属性email"受保护,只能在SignUpComponent"类及​​其子类中访问.

/src/app/views/signup/signup.component.html (21,86): Property 'email' is protected and only accessible within class 'SignUpComponent' and its subclasses.

/src/app/views/signup/signup.component.html (26,80):属性password"受到保护,只能在SignUpComponent"类及​​其子类中访问.

/src/app/views/signup/signup.component.html (26,80): Property 'password' is protected and only accessible within class 'SignUpComponent' and its subclasses.

有人可以在这方面帮助我如何消除这些错误吗?当我省略 --target=production 时,构建成功但过去我遇到的问题是没有指定目标浏览器缓存旧的部署版本,用户必须删除浏览器缓存才能影响最新的更改/部署.

Can someone please help me in this regard that how can I remove these errors? The build is successful when I omit --target=production BUT in past I got issue that without specifying target browser cache the old deployment version and user has to delete the browser cache to effect latest changes/deployment.

推荐答案

您的电子邮件和密码属性是否定义为私有?它们是否在组件的模板中使用?然后需要将它们从私有更改为公共.

Are your email and password properties defined to be private? Are they used in the component's template? Then they need to be changed from private to public.

当您使用 Angular CLI 的生产模式时,您会自动获得以下内容:

When you use the Angular CLI's production mode, you automatically get the following:

  • --aot 设置为 true
  • --output-hashing 设置为所有(指纹资产)
  • --sourcemaps 设置为 false
  • --extract-css 设置为 true(为全局样式制作真实的 css 文件,而 dev 制作 .js 文件作为重建优化)
  • 如果在 CLI json 中配置,则添加 Service Worker
  • 将模块中的 process.env.NODE_ENV 替换为 production 值(某些库需要此值,例如 react)
  • 在代码上运行 uglify
  • --aot is set to true
  • --output-hashing is set to all (fingerprints assets)
  • --sourcemaps is set to false
  • --extract-css is set to true (makes real css files for global styles, while dev makes .js files as a rebuild optimization)
  • adds service worker if configured in the CLI json
  • replaces process.env.NODE_ENV in modules with the production value (this is needed for some libs, like react)
  • runs uglify on the code

查看更多信息:https://github.com/angular/angular-cli/pull/6232

最有可能产生这些错误的是 aot 编译器.aot 编译器在 TypeScript 中编译模板,因此会生成更多类型错误.所以另一种选择是使用 --prod 而不使用 aot.

It is the aot compiler that is most likely generating these errors. The aot compiler compiles the template in TypeScript and hence generates more type errors. So another alternative is to use the --prod without aot.

这篇关于Angular ng build --target=production 给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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