查看“︁Node.js/npm/依赖检查”︁的源代码
来自康健生活
←
Node.js/npm/依赖检查
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 依赖包管理 == * dependencies: 生产环境依赖包管理 * devDependencies: 开发环境依赖包管理 * optionalDependencies: 可选择依赖包管理,当可选择依赖下载或安装失败不影响 npm 运行进程,可选择依赖覆盖生产环境依赖。等同于编译语言中的 try catch 机制。 * peerDependencies: 指定当前项目作为 package 被安装时的依赖限定条件 * bundledDependencies: 捆绑依赖包管理 == 依赖关系 == 原生的 npm 命令检查已安装的依赖关系和版本,并与当前源中的最新版本进行比较。 {{shc|<syntaxhighlight lang="bash"> npm outdated</syntaxhighlight>|$|/home/kwy}} {{shc|<syntaxhighlight lang="bash"> npm update</syntaxhighlight>|$|/home/kwy}} {{shc|<syntaxhighlight lang="bash"> npm upgrade</syntaxhighlight>|$|/home/kwy}} {{Linenum|1.}} 除此之外可以使用 npm-check-updates {{Version date|18.0.1|2025-4-24}} 对依赖进行更细致的分析。 {{shc|<syntaxhighlight lang="bash"> npm install -g npm-check-updates</syntaxhighlight>|$|/home/kwy}} 运行命令 {{Shc_out|<syntaxhighlight lang="bash"> ncu</syntaxhighlight>|<syntaxhighlight lang="bash"> Using pnpm Checking /home/kwy/postlab-core/packages/codemirror-input/package.json [====================] 70/70 100% @codemirror/autocomplete 6.18.1 → 6.18.6 @codemirror/lang-javascript 6.2.2 → 6.2.4 // ... xml-formatter 3.6.3 → 3.6.6 Run ncu -u to upgrade package.json </syntaxhighlight>|$|/home/kangkk}} == 依赖清理 == 依赖的清理有几种常见场景 {{linenum|1.}} 清理 <code>node_modules 中存在,但 package.json 中不存在</code> 的依赖项。 {{shc|<syntaxhighlight lang="bash"> npm prune </syntaxhighlight>|$|/home/kangkk}} {{linenum|2.}} 检查 <code>package.json 中未使用</code> 的依赖项。 {{shc|<syntaxhighlight lang="bash"> npm install -g depcheck</syntaxhighlight>|$|/home/kangkk}} 运行 depcheck {{Version_date|1.4.7|2023-10-17}} 来检查未使用的依赖 {{Shc_out|<syntaxhighlight lang="bash"> depcheck</syntaxhighlight>|<syntaxhighlight lang="bash"> Unused dependencies * @codemirror/lang-json // ... * workbox-window Unused devDependencies * @import-meta-env/unplugin // ... * vite-plugin-static-copy </syntaxhighlight>|$|/home/kangkk}} {{linenum|3.}} 检查 <code>package.json 中过时</code> 的依赖项。 {{shc|<syntaxhighlight lang="bash"> npm install -g npm-check</syntaxhighlight>|$|/home/kangkk}} 运行 npm-check {{Version_date|6.0.1|2022-7-17}},实测检查内容有些臃肿。类似的还有 npm-check-unused {{Version_date|6.0.0|2018-7-2}} (forked from dylang/npm-check),所以不做参考,不建议使用。 {{shc_out|<syntaxhighlight lang="bash"> npm-check -u -g</syntaxhighlight>|<syntaxhighlight lang="text"> ❤️ Your modules look amazing. Keep up the great work. ❤️ </syntaxhighlight>|kangjian@kangkk:~/tongdunol$}} {{shc_out|<syntaxhighlight lang="bash"> npm-check -u</syntaxhighlight>|<syntaxhighlight lang="text"> ? Choose which packages to update. (Press <space> to select) Missing. You probably want these. ❯◯ marked-toc missing 0.3.0 https://github.com/jonschlinkert/marked-toc // ... Minor Update New backwards-compatible features. ◯ moment missing 2.14.1 ❯ 2.27.0 https://momentjs.com // ... Major Update Potentially breaking API changes. Use caution. ◯ async missing 2.0.1 ❯ 3.2.0 https://caolan.github.io/async/ // ... Space to select. Enter to start upgrading. Control-C to cancel. </syntaxhighlight>|kangjian@kangkk:~/tongdunol$}}
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
模板:Linenum
(
查看源代码
)
模板:Linenum/style.css
(
查看源代码
)
模板:Shc
(
查看源代码
)
模板:Shc/style.css
(
查看源代码
)
模板:Shc out
(
查看源代码
)
模板:Shc out/style.css
(
查看源代码
)
模板:Version date
(
查看源代码
)
模板:Version date/style.css
(
查看源代码
)
返回
Node.js/npm/依赖检查
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。