【发布时间】:2020-02-14 06:08:59
【问题描述】:
我正在制作一个 react 项目,并在笔记本电脑和 Windows 10 桌面上使用 Linux mint。我想知道,我应该在 .gitignore 中保留哪些文件或文件夹,这样我在切换计算机时就不必清理缓存和安装 npm。
【问题讨论】:
我正在制作一个 react 项目,并在笔记本电脑和 Windows 10 桌面上使用 Linux mint。我想知道,我应该在 .gitignore 中保留哪些文件或文件夹,这样我在切换计算机时就不必清理缓存和安装 npm。
【问题讨论】:
何必呢?只需将您的浏览器指向gitignore.io 并选择您正在使用的所有工具和技术。您将自动生成一个.gitignore 文件。
【讨论】:
.gitignore 非常基本,不会涵盖所有内容 - 它甚至不包括 build 文件夹。来自 Facebook 的 .gitignore 应该涵盖所有内容 - github.com/facebook/react/blob/main/.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Distribution directories
dist/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
【讨论】:
如果您使用 create react app,则包含一个适用于 react 项目的好 .gitignore。你肯定想把 node_modules 保存在 gitignore 中。
【讨论】:
查看How to configure .gitignore file了解更多详情。
依赖关系
/node_modules
/.pnp
.pnp.js
package-lock.json
测试
/coverage
生产
/build
杂项
npm-debug.log*
【讨论】:
你可以在 react gitignore 中添加以下文件
.idea/
.vscode/
node_modules/
build
.DS_Store
*.tgz
my-app*
template/src/__tests__/__snapshots__/
lerna-debug.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/.changelog
.npm/
yarn.lock
【讨论】:
node_modules 应该始终放在 gitignore 和日志文件中(如果有的话)。休息由你决定。没有这样的标准
【讨论】:
我能找到的最接近“官方”.gitignore 的是在 Facebook git repo 下维护的开源 .gitignore - https://github.com/facebook/react/blob/main/.gitignore
【讨论】: