简体   繁体   English

构建一个可安装在我所有项目中的自定义NPM软件包

[英]Build a custom NPM package that can be installed in all my projects

I've built a custom style "skin" on top of bootstrap that I intend to use in multiple UI projects. 我在引导程序之上构建了自定义样式“皮肤”,打算在多个UI项目中使用它。

Rather than copying/pasting the UI styles/components (built using sass and typescript in my current Angular 5 project), I want to build an NPM package that I can install these styles and components I've built in new projects, thus allowing updates to be done to the NPM package (maybe extending the controls within for example) without breaking the UI's using them or needing to update files within. 我不想复制/粘贴UI样式/组件(在我当前的Angular 5项目中使用sass和typescript构建),而是想构建一个NPM软件包,可以安装在新项目中构建的这些样式和组件,从而允许更新可以对NPM软件包执行操作(例如,在其中扩展控件),而不会破坏UI使用它们或需要更新其中的文件。

I've never setup an NPM project before. 我以前从未设置过NPM项目。 I've found a number of examples of how to build NPM packages, for example https://codeforgeek.com/2014/08/how-to-create-nodejs-npm-package/ but it seems to be for vanilla JS in this example. 我找到了许多有关如何构建NPM软件包的示例,例如https://codeforgeek.com/2014/08/how-to-create-nodejs-npm-package/,但这似乎适用于这个例子。 I need an example which: 我需要一个示例:

  1. Builds on a dependency, in this case bootstrap 建立在依赖关系上,在这种情况下为引导程序
  2. Is to be used in Angular (I'm using version 5) 将在Angular中使用(我正在使用版本5)
  3. Is installable and updatable via NPM or maybe Yarn 可通过NPM或纱线进行安装和更新

Has anyone any top tips on achieving the above? 有没有人在实现上述目标方面有什么要诀? Or any really clear guides where someone has done this before? 或任何真正明确的指南,以前有人曾这样做过?

I realise this question is relatively broad but really I just need some pointers to get started and I will document the process further when I have a better understanding. 我意识到这个问题相对广泛,但实际上我只需要一些入门知识,当我有了更好的理解后,我将进一步记录该过程。

Thanks in advance! 提前致谢!

So you should move your theme into a separate project. 因此,您应该将主题移到一个单独的项目中。 Then all you have to do is run npm init in that directory and you have a npm. 然后,您所要做的就是在该目录中运行npm init ,您将拥有一个npm。

As for sharing it between projects, I would create a repo on Github for this theme npm. 至于在项目之间共享它,我将为此主题npm在Github上创建一个回购。 Push all of your changes there. 将所有更改推送到此处。 Then you can reference it in the package.json of all your projects by linking to the Github repo. 然后,您可以通过链接到Github存储库在所有项目的package.json中引用它。 Here is a good Stack question about how to do that. 这是有关如何执行此操作的一个很好的Stack问题

Finally, if you want to develop your theme locally inside one of your projects, you can use npm link . 最后,如果要在一个项目中本地开发主题,则可以使用npm link Here are he docs on that . 这是他的文档

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

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