How to share code between multiple projects with angularJS

后端 未结 3 588
刺人心
刺人心 2021-02-07 06:44

I was wondering what would be the best practice to share common libraries and own modules between multiple angularJS projects.

Let\'s assume that I\'m working on two dif

3条回答
  •  臣服心动
    2021-02-07 06:51

    Another potential option is to publish your shared code as npm modules. If the code is private then you can use npm Private Modules for that, although there is a cost for using private modules.

    With either this or the Bower approach described in d.jamison's answer try to break your modules into smaller modules based on their specific purposes, rather than having big monolithic "AllOurSharedCode" modules.

    The benefit of that is that if you find a bug, or make an improvement, you can see more easily exactly which of your projects may be affected. The require or ES2015 import syntax help a lot with that too as you will be saying e.g. import { calculateLineTotal } from OrderLogic.js, so it is then trivial to find all of the places in code that a change to the calculateLineTotal would impact.

提交回复
热议问题