角度ng build --target = production产生错误 [英] Angular ng build --target=production giving errors

查看:120
本文介绍了角度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):属性电子邮件"受保护,只能在类"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):属性密码"受保护,并且只能在"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中进行了配置,则会添加服务工作者
  • 在模块中将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

See this for more information: 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.

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

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