[Tengyu] postinstall-postinstall cooperates with patch-package to rewrite the dependency method of node_modules

1. Local installation dependencies (postinstall-postinstall, patch-package)

npm i patch-package postinstall-postinstall --save-dev

or

yarn add patch-package postinstall-postinstall

2. Modify package.json

Add { "postinstall": "patch-package" } to the scripts of package.json, which is a hook of npm and will be executed after the dependent package is installed

 

3. Modify the code in node_modules

 

4. Generate patches

npx patch-package your-package-name(修改的npm包名称,我的是el-tree-transfer)

  

5. After submitting the patches, re-install the package and you will find that it is the result of your modification

If it is found that after npm install, the dependency is restored to before it has been changed, you can execute the command: npm run postinstall

The operation effect is as follows

OK, done

Guess you like

Origin blog.csdn.net/qq_23334071/article/details/114736831