简体   繁体   English

ng add 之间的区别<package name>与 npm 安装<package name>在角 6

[英]Difference between ng add <package name> vs npm install <package name> in angular 6

As Angular6 has been released, They have added a new command ng add .随着 Angular6 的发布,他们添加了一个新命令ng add Can anyone tell me what will be the difference between existing command npm install <package> and ng add <package>谁能告诉我现有command npm install <package>ng add <package>之间有什么区别

ng add添加

ng add <package> uses your package manager and installs the dependency. ng add <package>使用您的包管理器并安装依赖项。 That dependency can have an installation script which can be used to do more job except the dependency installation.该依赖项可以有一个安装脚本,除了依赖项安装之外,该脚本可用于执行更多工作。 It can update your configurations, download another dependencies based on that one or create scaffold templates (with initial markup and logic ).它可以更新您的配置、下载基于该依赖项的另一个依赖项或创建脚手架模板(带有初始标记和逻辑)。

To use ng add for a third party dependency, that team must provide schematics which describes the installation script.要将ng add用于第三方依赖项,该团队必须提供描述安装脚本的原理图 This can include some .scss or .css or related .js files to be included in the angular.json file.这可以包括一些.scss.css或相关.js文件被列入angular.json文件。

In your provided link, you can install material package and also create some components with components在您提供的链接中,您可以安装材料包并使用组件创建一些组件

npm install安装

npm install <package> just installs the dependency. npm install <package>只是安装依赖项。

For more Version 6 of Angular Now Available .更多Angular 6 版本现已推出

ng add 添加

Will use your package manager to download new dependencies and invoke an installation script which can update your project with configuration changes (In angular.json file as well), add additional dependencies (eg polyfills if needed), or scaffold package-specific initialization code.将使用您的包管理器下载新的依赖项并调用安装脚本,该脚本可以使用配置更改更新您的项目( angular.json文件中),添加额外的依赖项(例如,如果需要的话),或脚手架特定于包的初始化代码。

For example you run the command ng add @angular/material — Install , it will automatically install the package and configure in angular.json file too.例如,您运行命令ng add @angular/material — Install ,它也会自动安装包并在angular.json文件中进行配置。

npm install安装

Whereas npm install <package> will only install your package into your project but will not configure in order to use.npm install <package>只会将您的包安装到您的项目中,而不会进行配置以使用。

For example you run the command npm install jquery it will install jQuery in your project but you need to configure manually in .angular-cli.json file (as in v5)例如,您运行命令npm install jquery它将在您的项目中安装 jQuery 但您需要在.angular-cli.json文件中手动配置(如在 v5 中)

For more information read out here -有关更多信息,请在此处阅读 -

As for Angular 7, take @ngrx/store package for example.至于 Angular 7,以@ngrx/store包为例。

Besides installing packages and adding them to package-lock.json and package.json , ng add will do these for you.除了安装包并将它们添加到package-lock.jsonpackage.jsonng add还会为你做这些。

1.Create file index.ts under reducers foler, and initialize root reducer. index.tsreducers文件index.ts下创建index.ts文件,并初始化root reducer。

 import { ActionReducer, ActionReducerMap, createFeatureSelector, createSelector, MetaReducer } from '@ngrx/store'; import { environment } from '../../environments/environment'; export interface State { } export const reducers: ActionReducerMap<State> = { }; export const metaReducers: MetaReducer<State>[] = !environment.production ? [] : [];

2.Add StoreModule to AppModule. 2. 将 StoreModule 添加到 AppModule。 (In file app.module.ts) (在文件 app.module.ts 中)

 import { StoreModule } from '@ngrx/store'; import { reducers, metaReducers } from './reducers'; @NgModule({ imports: [ StoreModule.forRoot(reducers, { metaReducers }), ] })

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

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