简体   繁体   English

Angular2 Production AOT构建与角度CLI

[英]Angular2 production AOT build with angular cli

My Angular2 web app consists of 我的Angular2网络应用包含

  • Third party plugins like jquery, pdfjs, etc 第三方插件,例如jquery,pdfjs等
  • Has services defined! 已定义服务!
export class WorkerService{
    constructor() {

    }
}

When I am building a Dev AOT build using angular cli, there was no problem! 当我使用angular cli构建Dev AOT构建时,没有问题! But when I am doing a Prod AOT build using angular cli, it gives me an error saying, "Unexpected token : name (WorkerService)". 但是,当我使用angular cli进行Prod AOT构建时,它给我一个错误,说“意外的令牌:名称(WorkerService)”。 The command I used is 我使用的命令是

ng build --prod --aot ng build --prod --aot

What might I be doing wrong?? 我可能做错了什么? I don't have a spec file related to my service, would that be a problem? 我没有与我的服务相关的规格文件,会不会有问题? Thanks. 谢谢。

Angular CLI version: 1.0.0-beta.25.5 Angular CLI版本:1.0.0-beta.25.5

在此处输入图片说明

This is an issue with the version of UglifyJs that is bundled with angular/cli. 这是与angular / cli捆绑在一起的UglifyJs版本的问题。 It's a release version and can only support compiled ES5 or lower. 它是发行版本,仅支持编译的ES5或更低版本。 Look into your tsconfig.app.json and see the target line, probably something like 查看您的tsconfig.app.json并查看目标行,可能类似于

{
  "compilerOptions": {
    ...
    "target": "es2016",
    ...
}

Change es2016, es2015, es6 or whatever you have to "es5", or create this file and add the target to it, and try building again. 将es2016,es2015,es6或任何您需要的内容更改为“ es5”,或创建此文件并向其中添加目标,然后尝试再次构建。 This worked for me but may not always work if you're using ES6 or ES2016 features that can't be transpiled back to ES5. 这对我有用,但如果您使用的ES6或ES2016功能无法转换回ES5,则可能并不总是有效。

tsconfig.json is obsolete but some IDEs like Visual Studio Code still use and I think tsconfig.spec.json is used during building and running tests. tsconfig.json已过时,但某些IDE(如Visual Studio Code)仍在使用,我认为tsconfig.spec.json在构建和运行测试期间使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM