In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to manually configure the dependency package in node_modules". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First of all, the problem is that the third-party plug-in pdfvuer is used in the project to display the pdf that has been successfully stamped. At this time, it is found that the article can be well displayed, but the company's signature can not be displayed. This time finally found a solution! However, the modification code that displays the signature is in the node_modules path of the dependency package. After all, the file under node_modules needs to be modified manually every time the npm install is modified. In an instant, I began to feel bad, but I still had to find a way to solve it.
There were two options that came to mind at first:
Fork other people's code to your own warehouse, modify it, and install the plug-in from your own warehouse.
Download other people's code locally, put it in the src directory, and manually introduce it after modification. There are also many inconveniences to do so, such as it is cumbersome and time-consuming to package your own components, and it will also make the project look bloated.
However, either of the above methods are too complex, I changed a file to one or two lines of code, but such a bloated copy the whole project, may end up forgetting where to change, and update trouble, we need to update the code manually every time, can not synchronize with the plug-in update. In this case, I turned my head and began my road to knowledge again. Then I found a high-end solution to modify dependency packages in node_modules with patch-package.
Solution
1. Install patch-package through the command
`npm install patch-package-- save- dev`
two。 Modify the package.json file under the root of the project
Add "postinstall": "patch-package" to the scripts in the package.json file
3. Manually modify the source code in the node_modules dependency package
4. Manually execute the command to create a npx patch-package package-name patch file
`npx patch-package package- name`
Where package-name is the name of the dependent package to be modified. After executing this command, a patches folder is automatically created in the root directory of the project, and a patch file for package-name+version.patch appears in the folder. As shown in the figure:
For example: I want to modify the file under pdfjs-dist, so the command I execute is: npx patch-package pdfjs-dist
5. Test whether the patch pack is valid
Manually delete the node_modules file in the project (force deletion of the node_modules folder: rimraf node_modules) and re-execute the npm install command to install the node_modules dependency package. After successful installation, check the files in your previously modified node_modules dependency package to see if your modified code still exists, if the previously modified code still exists, it means that the patch file has taken effect, if your previously modified code does not exist, it means the patch file does not take effect.
This is the end of "how to manually configure dependency packages in node_modules". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.