We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
假设 lodash 有一个 Bug,影响线上开发,应该怎么办?
lodash
答: 三步走。
很合理很规范的一个流程,但是它一个最大的问题就是,太慢了,三步走完黄花菜都凉了。
此时可直接上手修改 node_modules 中 lodash 代码,并修复问题!
node_modules
新问题:node_modules 未纳入版本管理,在生产环境并没有用。请看流程
node_modules/lodash
npm i lodash
此时有一个简单的方案,临时将修复文件纳入工作目录,可以解决这个问题
${work_dir}/patchs/lodash
但此时并不是很智能,且略有小问题,演示如下:
此时有一个万能之策,那就是 patch-package
想要知道 patch-package 如何解决上述问题,请先了解下它的用法,流程如下
patch-package
# 修改 lodash 的一个小问题 $ vim node_modules/lodash/index.js # 对 lodash 的修复生成一个 patch 文件,位于 patches/lodash+4.17.21.patch $ npx patch-package lodash # 将修复文件提交到版本管理之中 $ git add patches/lodash+4.17.21.patch $ git commit -m "fix 一点儿小事 in lodash" # 此后的命令在生产环境或 CI 中执行 # 此后的命令在生产环境或 CI 中执行 # 此后的命令在生产环境或 CI 中执行 # 在生产环境装包 $ npm i # 为生产环境的 lodash 进行小修复 $ npx patch-package # 大功告成!
再次看下 patch-package 自动生成 patch 文件的本来面目吧:
它实际上是一个 diff 文件,在生产环境中可自动根据 diff 文件与版本号 (根据patch文件名存取) 将修复场景复原!
diff
$ cat patches/lodash+4.17.21.patch diff --git a/node_modules/lodash/index.js b/node_modules/lodash/index.js index 5d063e2..fc6fa33 100644 --- a/node_modules/lodash/index.js +++ b/node_modules/lodash/index.js @@ -1 +1,3 @@ +console.log('DEBUG SOMETHING') + module.exports = require('./lodash'); \ No newline at end of file
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: