Browse Source

Docsify Auto Published

Willin Wang 7 years ago
parent
commit
b72e360267
1 changed files with 18 additions and 0 deletions
  1. 18 0
      basic/node/yarn.md

+ 18 - 0
basic/node/yarn.md

@@ -1,5 +1,23 @@
 # Yarn 进阶使用
 
+## 批量升级所有依赖项并更新 package.json
+
+```js
+const pack = require('./package.json');
+const { execSync } = require('child_process');
+
+const list = [...Object.keys(pack.devDependencies), ...Object.keys(pack.dependencies)];
+// 忽略的项目 (不用升级)
+const ignore = ['eslint', 'babel-cli'];
+
+list.forEach((item) => {
+  if (!ignore.includes(item)) {
+    console.log(`yarn upgrade ${item}`);
+    execSync(`yarn upgrade ${item}`);
+  }
+});
+```
+
 ## 忽略 Node.js 要求
 
 比如, 有一些包指定了 Node.js 版本的要求, 如: