角度ng build --target = production产生错误 [英] Angular ng build --target=production giving errors
问题描述
我已经使用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 theproduction
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屋!