美文网首页
如何优雅的修改node_modules中的依赖库

如何优雅的修改node_modules中的依赖库

作者: 艾希_可可 | 来源:发表于2021-05-19 11:31 被阅读0次

    弄一个解决这类问题的npm包,然后又按常例的事先google了一番,结果却发现已经存在了这么一个东东,patch-package(<u style="text-decoration: none; border-bottom: 1px dashed grey;">https://www.npmjs.com/package/patch-package</u>),一看发布时间是两年前,如果我没中途去做吃鸡手游,也许这个库最先可能是被我弄出来的,哈哈。

    既然不需要我再造一个轮子了,那接下来我就分享下怎么使用吧。

    1.本地安装,npm i patch-package

    2.在package.json 的scripts中加入 { "postinstall": "patch-package" },这是npm的一个钩子,会在依赖包被install之后执行

    3.修改node_modules中的代码

    4.生成patches,npx patch-package your-package-name


    image.png

    5.提交patches后,重新install包你就会发现是你修改后的结果

    最后,这个库的官网还有一段很详细的对比,描述了什么时候用patch什么时候fork,描述的非常到位:

    转载来自https://zhuanlan.zhihu.com/p/85574731
    别忘了要先做这些事情
    1、修改node_modules文件
    2、提交代码仓库
    !/node_modules
    /node_modules/*
    !/node_modules/xss
    /node_modules/xss/*
    !/node_modules/xss/lib
    /node_modules/xss/lib/*
    !/node_modules/xss/lib/default.js

    相关文章

      网友评论

          本文标题:如何优雅的修改node_modules中的依赖库

          本文链接:https://www.haomeiwen.com/subject/bjjmdktx.html