Toggle navigation
集客麦麦@谢坤
首页
随笔
首页
>>
创作中心
>>
patch-pack...
patch-package 包补丁工具使用
Not Found
# 1. 安装 patch-package `npm i patch-package --save-dev` # 2. "postinstall": "patch-package" package.json scripts 项添加 "postinstall": "patch-package" package.json ```js { "name": "patch_pkg", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "postinstall": "patch-package" }, "author": "", "license": "ISC", "devDependencies": { "jQuery": "^1.7.4", "patch-package": "^6.4.7" } } ``` # 3. 修改包代码 以JQuery为例: node_modules\jQuery\README.md文件 尾部添加: `# this is patch-package test` # 4. 生成包补丁文件 回到package.json 根路径 运行: --- `yarn patch-package jQuery` 或 --- npm 全局安装patch-package: 'npm patch-package -g' 直接运行: `patch-package jQuery` 将在根目录生成 `patches` 目录文件记录补丁文件 # 5. 如何测试补丁成功 以上步骤后将将 node_package 删掉, 运行 npm i 时将自动在安装包时将补丁写入打包文件,检查上例jQuery 的 node_modules\jQuery\README.md 文件,此时已在尾部加入了上次修改的代码