在前端我的项目开发中,咱们常常会遇到node_modules里的包有问题,当本人手动更改成正确的后,本人没问题了,然而他人从新npm install时还会有同样的问题,那么如何将node_modules的更改保留到我的项目中呢,这样他人在生成依赖后能有一个失常的环境

通过:

patch-package这个包能够在npm install后依照我的项目里保留的更改主动批改node_modules,十分好用

应用步骤:

一.装置

能够应用npm

npm i patch-package -D

或yarn(postinstall-postinstall 确保在yarn remove时仍旧能放弃更正代码)

yarn add patch-package postinstall-postinstall

二.设置

装置完后须要给package.json设置postinstall,在装置完node_modules后会主动执行

"scripts": {  "postinstall": "patch-package"}

三.应用

  • 批改node_modules的内容
  • npx patch-package 批改的包名(执行实现后,会在我的项目目录生成一个文件夹,保留着此次批改的内容)
  • 通过git推到近程仓库,这样其余小伙伴也能够用了