转换现有的angular 2项目以使用angular CLI [英] Converting an existing angular 2 project to use angular CLI

查看:90
本文介绍了转换现有的angular 2项目以使用angular CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不是使用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项目中才能使用generate命令.

You have to be inside an angular-cli project in order to use the generate command.

有没有办法将现有项目转换为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:

  1. 创建一个新的角度项目 ng new myTemplate

  1. Create a new angular project ng new myTemplate

将相关文件从新的myTemplate项目复制到现有项目:

Copy relevant files to your existing project from your new myTemplate project:

.angular-cli.json package.json tslint.json src/polyfills.ts src/styles.css src/tsconfig.json

.angular-cli.json package.json tslint.json src/polyfills.ts src/styles.css src/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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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