社区提供了一个工具:[patch-
package](https://links.jianshu.com/go?to=https%3A%2F%2Fgithub.com%2Fds300%2Fpatch-
package),专门用来处理修改 node_modules 包源码的问题。
修改package.json,添加最后一行: "postinstall": "patch-package",postinstall 是 npm
的钩子,会在依赖包被 install 之后被执行。
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint .",
"postinstall": "patch-package"
},
之后安装patch-package这个库,
npm i patch-package -D
或者
yarn add patch-package postinstall-postinstall -D
注意二者是有区别的。
配置、安装好了之后,我们就可以直接修改第三方包的内容了,修改完之后,运行:
npx patch-package [package-name]
或者
yarn patch-package [package-name]
修改完之后,项目根目录下就多出来一个patches文件夹
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。