This is a very generic question and I have been wondering this for a while.
I am working on an angular application, and I am using few open source npm packages. One way is to npm install these packages and then use the provided features in that way. But I think ( haven't try ) there is another way which is directly pull the source code from the open source project and then embed the code into my application. It should work. The benefit is that I can easily modify the open source code to fit my needs.
Is that true and feasible?
appreciate your andswer and thanks in advance!
CodePudding user response:
There's a few reasons you might not want to take this approach:
- LEGAL: Open source code usually has rules about its reuse, stating that you must include a particular license or attribution; grabbing the code without doing your due diligence and making sure you are using it properly could wind you up in some sort of legal hot water.
- SECURITY/STABILITY: Open source code is generally being constantly iterated on to provide security patches, bug fixes, and other improvements. Grabbing wholesale chunks of code and hardcoding them into your site fully decouples you from this process.
- ORGANIZATION: Leveraging open source code with a package manager like
npm
gives you insight into all the packages you are using, the specific version you are using, and peer dependencies you might require. Separating yourself from this with hardcoding means much more mystery should things start to go wrong.
While grabbing a small snippet from a library and adjusting it for your needs might be feasible in certain cases that are limited in size and scope, I would not make a habit of doing so. Alternatives would be submitting a PR to the library in question to provide the behavior you require, or forking the library and maintaining a separate version (that way you could pull in upstream changes).
CodePudding user response:
I really recommend using npm install
to use it in your angular app.
If you want to change the code source of that open source library, I suggest the following :
- First fork the library in your github
- perform your changes
- Publish the forked library as a new npm package
- npm install
your new forked library
Note : Please be carefull to the liscence of open source project. You should be aware of the LEGAL rights that allow you to do that.