Should you commit the node_modules directory to git? This is a very valid question. You need to consider both the advantages and disadvantages here.
I will cover this topic in this article so that you can come to your conclusion.
Here we discuss .gitignore, however, what we discuss here applies in the case of all other version control systems you use, The default option here is not. must to commit the node_modules directory. Instead, you should add it to the .gitignore file.
To handle this, you must have special needs.
Why shouldn't you hand over the node_modules directory to Git?
Let's take a look at some of the arguments in favor of committing node_modules below.
Keeping the Git clan history is essential. When it's time to add a new package, you store the file changes in package-lock.json and package.json. However, in case of updating a package, you only need to store the file changes in package-lock.json.
As far as package-lock.json is concerned, this is not an old feature of npm. It is an alternative to shrink command that has become obsolete. The best thing about this is that it's faster with the fact that you don't have to put a few megabytes depending on the repository. Talking about the repository size, code checking, and switching branches are affected by this.
Coming to affiliates, you may have to deal with consolidation conflicts. Maybe it is smart to involve code dependencies. This can be time consuming. It would be better to avoid such a scenario.
Sometimes changing dependencies affects a lot of files in the process. Tools tend to be slower in such situations. In some cases, the tools may refuse to show the full difference. We can take GitHub as an example here.
In the event that the deployed platform differs from the development machine, you need to recompile the root node modules. You may have developed it on Mac, but are planning to deploy it on Linux. Here you need to call the rebuild npm.
When you do not commit node_modules, you must list all your modules in package-lock.json and package.json. That is a beautiful thing. If you don't do this, npm's performance may be affected, which should be avoided.
Tip: Thanks to the advent of the package-lock.json file, you don't need to use a specific version in the package.json file.
When you commit the node_modules directory, you are just committing developer dependencies. What's more, production builds can be difficult to get rid of.
Let’s have a look at the reasons that would prompt you to commit node_modules.
We will also tell you how to mitigate them.
The author can remove the npm package from the registry. The now-famous left-pad incident which happened in 2016 is an example. Such incidents rarely happen for popular packages. In case it happens, you may have lost access to the specific functionality.
There is this popular argument that npm might not be around for long. Yes, it could disappear someday. Given that, committing your code sounds like a smart idea.
Whenever you use a package, the GitHub fork should be created. Moreover, you need to keep it up to date as well. However, this can be automated as well.
However, I wouldn’t call it the most practical idea since packages come with their baggage of dependencies.
We recommend using a private repository server. You can host all your dependencies here.
You have the following options:
- npm enterprise
- artifactory
- npm lazy mirror
- npm lazy
- sinopia
If you commit the dependencies, you will be able to edit the code quickly. You can easily add an element to the library as well.
However, it comes with disadvantages as well. When you go for this, you will not be able to upgrade the package when new releases come to the fore. If we are talking about temporary fixes, then it is recommended.
We recommend submitting a PR. Alternatively, you can fork it.
Resouce: https://www.positronx.io/should-i-commit-the-node_modules-folder-to-git/
No comments:
Post a Comment