简体   繁体   English

在创建新的 Angular 项目时包含 .npmrc

[英]Include .npmrc while creating a new angular project

I am creating a command line application using node.js.我正在使用 node.js 创建一个命令行应用程序。 The application wraps the ng new command from angular CLI.该应用程序包装了来自 angular CLI 的ng new命令。 While creating a new angular project, dependencies are installed automatically.在创建新的 angular 项目时,会自动安装依赖项。

The problem here is we are using a private npmjs repository which at times may not have some specified dependencies in it.这里的问题是我们使用了一个私有的 npmjs 存储库,它有时可能没有一些指定的依赖项。 To avoid this situation, I thought to have a .npmrc file in which I can define to fetch the organization specific node modules from the private repository and rest of the node modules from the npm repository.为了避免这种情况,我想有一个 .npmrc 文件,我可以在其中定义从私有存储库中获取组织特定的节点模块,并从 npm 存储库中获取其余的节点模块。

Is there any way, using which I can add a .npmrc file during angular project creation with the command ng new?有什么方法可以在使用 ng new 命令创建角度项目期间使用它添加 .npmrc 文件吗?

Thanks in advance提前致谢

You can do this to avoid using global config:您可以这样做以避免使用全局配置:

  1. Make a project directory制作项目目录
  2. Add a .yarnrc file to your project directory with your desired registry like: registry= https://registry.npmjs.org/使用所需的注册表将 .yarnrc 文件添加到您的项目目录,例如:registry= https://registry.npmjs.org/
  3. Then yarn init in the directory然后在目录下yarn init
  4. Then yarn add ng so it adds ng from the repository you listed然后yarn add ng所以它从你列出的存储库中添加 ng
  5. Continue with ng new ${yourprojectname} to use the local ng you just created继续ng new ${yourprojectname}使用你刚刚创建的本地 ng
  6. After ng new creates the angular directory, you may want to also copy the .npmrc and .yarnrc inside the project and configure them with your desired registry and run npm install just to be sure.在 ng new 创建 angular 目录后,您可能还想复制项目中的 .npmrc 和 .yarnrc 并使用所需的注册表配置它们并运行npm install以确保。

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

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