Node.js 的 .gitignore

适用于 Node.js 的 63 条忽略规则,可直接复制到您的仓库。

基于 Chrome V8 引擎的 JavaScript 运行时

Node.js 的完整 .gitignore

# 由 LFGitignore - https://lfgitignore.com 生成
# 创建:2026-10-31 21:49:47 UTC
# 技术:Node.js

### Node.js ###
logs
# Node.js 诊断报告
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# 进程ID文件
pids
# 进程ID文件
*.pid
# 随机种子文件
*.seed
# 进程锁文件
*.pid.lock
# Lerna 调试日志
lerna-debug.log*
# 库覆盖范围
lib-cov
# 日志档案
*.log
# 覆盖目录
coverage
# LCOV 覆盖数据
*.lcov
# TypeScript 构建信息
*.tsbuildinfo
# NYC 覆盖率输出
.nyc_output
# npm 调试日志
npm-debug.log*
# Grunt 中间存储
.grunt
# Yarn调试日志
yarn-debug.log*
# Bower 依赖项
bower_components
# Yarn错误日志
yarn-error.log*
# 节点-waf配置
.lock-wscript
# 编译的二进制插件
build/Release
# Node.js 依赖项
node_modules/
# JSPM 包
jspm_packages/
# Snowpack 模块
web_modules/
# npm 缓存目录
.npm
# ESLint 缓存
.eslintcache
# Stylelint 缓存
.stylelintcache
.node_repl_history
*.tgz
.yarn-integrity
# 环境变量
.env
.env.*
!.env.example
# 缓存目录
.cache
# Parcel 打包器缓存
.parcel-cache
# Next.js 构建输出
.next
# Next.js 静态导出
out
# Nuxt.js 构建输出
.nuxt
dist
.cache/
# Nitro/Nuxt 生产构建输出
.output
# VuePress 构建输出
.vuepress/dist
# 临时文件
.temp
.svelte-kit/
**/.vitepress/dist
**/.vitepress/cache
# Docusaurus 缓存
.docusaurus
# 无服务器框架
.serverless/
# FuseBox 缓存
.fusebox/
# 本地 DynamoDB
.dynamodb/
.firebase/
# Tern.js 端口文件
.tern-port
# VS Code 测试目录
.vscode-test
.pnpm-store
# Yarn Plug'n'Play 文件
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.vite/

这些 Node.js 规则实际上忽略了什么

以下列出了每个忽略模式及其加入 .gitignore 的原因。

日志

模式 忽略的内容
logs 日志
lerna-debug.log* Lerna 调试日志
*.log 日志档案
npm-debug.log* npm 调试日志
yarn-debug.log* Yarn调试日志
yarn-error.log* Yarn错误日志

诊断报告 (https://nodejs.org/api/report.html)

模式 忽略的内容
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json Node.js 诊断报告

运行时数据

模式 忽略的内容
pids 进程ID文件
*.pid 进程ID文件
*.seed 随机种子文件
*.pid.lock 进程锁文件

jscoverage/JSCover 生成的检测库的目录

模式 忽略的内容
lib-cov 库覆盖范围

伊斯坦布尔等工具使用的覆盖目录

模式 忽略的内容
coverage 覆盖目录
*.lcov LCOV 覆盖数据
.nyc_output NYC 覆盖率输出

TypeScript 缓存

模式 忽略的内容
*.tsbuildinfo TypeScript 构建信息

Grunt 中间存储 (https://gruntjs.com/creating-plugins#storing-task-files)

模式 忽略的内容
.grunt Grunt 中间存储

Bower 依赖目录 (https://bower.io/)

模式 忽略的内容
bower_components Bower 依赖项
.lock-wscript 节点-waf配置

已编译的二进制插件 (https://nodejs.org/api/addons.html)

模式 忽略的内容
build/Release 编译的二进制插件

依赖目录

模式 忽略的内容
node_modules/ Node.js 依赖项
jspm_packages/ JSPM 包

Snowpack 依赖目录 (https://snowpack.dev/)

模式 忽略的内容
web_modules/ Snowpack 模块

可选的 npm 缓存目录

模式 忽略的内容
.npm npm 缓存目录

可选的 eslint 缓存

模式 忽略的内容
.eslintcache ESLint 缓存

可选的 stylelint 缓存

模式 忽略的内容
.stylelintcache Stylelint 缓存

可选的 REPL 历史记录

模式 忽略的内容
.node_repl_history 可选的 REPL 历史记录

“npm pack”的输出

模式 忽略的内容
*.tgz “npm pack”的输出

Yarn完整性文件

模式 忽略的内容
.yarn-integrity Yarn完整性文件
.env 环境变量
.env.* Yarn完整性文件
!.env.example Yarn完整性文件
.cache 缓存目录
.parcel-cache Parcel 打包器缓存

Next.js 构建输出

模式 忽略的内容
.next Next.js 构建输出
out Next.js 静态导出

Nuxt.js 构建/生成输出

模式 忽略的内容
.nuxt Nuxt.js 构建输出
dist Nuxt.js 构建/生成输出
.output Nitro/Nuxt 生产构建输出

Gatsby 文件

模式 忽略的内容
.cache/ Gatsby 文件
.vuepress/dist VuePress 构建输出
.temp 临时文件

Sveltekit缓存目录

模式 忽略的内容
.svelte-kit/ Sveltekit缓存目录
**/.vitepress/dist vitepress 构建输出
**/.vitepress/cache vitepress缓存目录

Docusaurus 缓存和生成的文件

模式 忽略的内容
.docusaurus Docusaurus 缓存

无服务器目录

模式 忽略的内容
.serverless/ 无服务器框架

FuseBox 缓存

模式 忽略的内容
.fusebox/ FuseBox 缓存

DynamoDB 本地文件

模式 忽略的内容
.dynamodb/ 本地 DynamoDB

Firebase 缓存目录

模式 忽略的内容
.firebase/ Firebase 缓存目录

TernJS 端口文件

模式 忽略的内容
.tern-port Tern.js 端口文件

存储用于测试 Visual Studio Code 扩展的 Visual Studio Code 版本

模式 忽略的内容
.vscode-test VS Code 测试目录
.pnpm-store pnpm
.pnp.* Yarn Plug'n'Play 文件
.yarn/* 存储用于测试 Visual Studio Code 扩展的 Visual Studio Code 版本
!.yarn/patches 存储用于测试 Visual Studio Code 扩展的 Visual Studio Code 版本
!.yarn/plugins 存储用于测试 Visual Studio Code 扩展的 Visual Studio Code 版本
!.yarn/releases 存储用于测试 Visual Studio Code 扩展的 Visual Studio Code 版本
!.yarn/sdks 存储用于测试 Visual Studio Code 扩展的 Visual Studio Code 版本
!.yarn/versions 存储用于测试 Visual Studio Code 扩展的 Visual Studio Code 版本

Vite 文件

模式 忽略的内容
vite.config.js.timestamp-* Vite 文件
vite.config.ts.timestamp-* Vite 文件
.vite/ Vite 文件

如何将此 .gitignore 用于 Node.js

  1. 复制上面的Node.js规则,或者直接下载文件。
  2. 在 Git 仓库根目录创建名为 .gitignore 的文件,并将规则粘贴进去。
  3. 如果其中一些文件已被跟踪,请运行 git rm -r --cached . 然后再次提交 - Git 仅将忽略规则应用于未跟踪的文件。
  4. 提交 .gitignore 以便团队中的每个人都共享相同的规则。

其他 运行时 .gitignore 模板

查看每个 运行时 模板