问题描述
我有一个不是使用ng new
创建的项目(相反,我遵循了 quickstart 指导).当我在该项目中运行有角度的CLI命令(例如ng generate
)时,出现以下错误消息:
I have a project that was not created using ng new
(rather, I followed the quickstart guide). When I run an angular CLI command in that project (such as ng generate
) I get this error message:
有没有办法将现有项目转换为angular-cli项目? (我想尝试使用它,因为它显然可以自动解决桶输入和SystemJS问题.)
Is there a way I can turn my existing project into an angular-cli project? (I wanted to try using it because it apparently automatically works around an issue with barrel imports and SystemJS.)
推荐答案
您应该能够运行ng init
并按照提示进行操作.如果您需要一些指导,请查看此问题: https://github.com/angular/angular-cli/issues/755
You should be able to run ng init
and follow the prompts. Have a look at this issue if you need some guidance: https://github.com/angular/angular-cli/issues/755
编辑(2017年3月13日):
ng-init
已从最新版本的cli中删除. https://github.com/angular/angular-cli/pull/4628
ng-init
was removed from the latest version of the angular cli.https://github.com/angular/angular-cli/pull/4628
因此,现在您需要模仿其试图完成的工作.即:
So for now you'll need to resort to mimicking what it tried to accomplish.ie:
-
创建一个新的角度项目ng new myTemplate
Create a new angular projectng new myTemplate
将相关文件从新的myTemplate项目复制到现有项目:
Copy relevant files to your existing project from your new myTemplate project:
.angular-cli.jsonpackage.jsontslint.jsonsrc/polyfills.tssrc/styles.csssrc/tsconfig.json
.angular-cli.jsonpackage.jsontslint.jsonsrc/polyfills.tssrc/styles.csssrc/tsconfig.json
根据您现有应用程序的状态,您可能希望通过某种方式进行复制.我猜这就是为什么从CLI中删除该功能的原因.它实际上没有任何方法可以确切地知道您要执行的操作.
Depending on the state of your existing application you may want to copy over way more or way less. I guess this is why the feature was removed from the CLI. There isn't really any way for it to know exactly what you want it to do.
这篇关于转换现有的angular 2项目以使用angular CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!