Take a look at how front-end engineering using NPM can modify the source code in node_modules without affecting deployment.
Use two packages: patch-package and postinstall-postinstall(for yarn compatibility).
The installation
$ yarn add patch-package postinstall-postinstall -D
Copy the code
Modify the source code
Find the third party library source code that you want to modify
Generate a Change record
$ npx patch-package ${package_name}
Copy the code
Change ${package_name} to the third-party package name you just modified, such as element-ui. At this point, a Patches directory is created in the root of the project, which contains the changes to the third-party package (git diff).
Add a script
Add a new record to the scripts of package.json:
{
"scripts: { "postinstall":"patch-package",... }}Copy the code
Postinstall is a hook for NPM. Postinstall-postinstall is executed after NPM install or yarn (or yarn remove). Therefore, we will complete the adjustment of the third party pack in the Patches catalog.
Commit changes
Thanks for reading!!