如何在本地安装 Angular CLI(没有 -g 标志) [英] How to install Angular CLI locally (without the -g flag)
问题描述
我刚刚开始使用 Angular 和 Angular-CLI,我已经看到,根据文档,我需要安装 $ npm install -g @angular/cli
带有 -g
(全局)标志.
I've just started working with Angular and with Angular-CLI and I've seen that, according to the documentation, I need to install $ npm install -g @angular/cli
with the -g
(global) flag.
但是,我希望将 Angular-CLI 与我的其余 node_modules 包一起安装在本地.这样,当我从 git 下载我的项目时,我可以简单地运行 $ npm install
(用于安装我的 package.json 中的所有依赖项强>).
However I would like to have Angular-CLI installed locally with the rest of my node_modules packages. This way, when I've download my project from git, I could simply run $ npm install
(for installing all the dependencies in my package.json).
我尝试通过运行 $ npm init
来创建一个新项目,然后运行 $ npm i @angular/cli -D
(-D
与 --save-dev
相同).但是当我运行 $ ng new project-name
时,会创建一个新的子目录,其中包含一个单独的 node_modules 目录.
I try to create a new project by running $ npm init
and then run $ npm i @angular/cli -D
(-D
is the same as --save-dev
). But then when I run $ ng new project-name
a new sub directory was created with a separate node_modules directory.
推荐答案
正如一些评论所建议的,您可以在您的系统上拥有本地和全局版本的 angular cli.
As some of the comments suggest, you can have a local and global version of angular cli on your system.
为了能够访问您的本地版本而不是全局版本(假设您在本地安装了不同的版本然后全局安装)使用 npm run-script ng
To be able to access your local version instead of global (lets say you have a different version installed locally then your global install) use npm run-script ng
例如npm run-script ng 生成组件 SomeCoolComponent
在 github 上查看类似问题的答案:https:///github.com/angular/angular-cli/issues/5955#issuecomment-320273493
check out this answer on github to a similar question: https://github.com/angular/angular-cli/issues/5955#issuecomment-320273493
这篇关于如何在本地安装 Angular CLI(没有 -g 标志)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!