node_modules 文件夹是否需要 commit

本人刚开始使用一些npm命令,请问假如使用npm安装了某个包,是否需要 git commit 提交, 例如使用 npm 安装了 bootstrap,然后使用 webpack 打包成单个 bundle.js 文件,那么node_modules文件夹需要提交吗?

产生这个困惑是因为自己练习的过程中观察到npm安装的包文件的体积都较大(node_modules文件夹体积比自己工作的主要两个文件index.html和main.js体积大多了)

另外,例如gulpfile.js,pack.json, webpack.config.js 等等这些文件需要提交吗?
关于开发过程中某个文件是否提交,有何方法论可以说说?
望大神不吝赐教。

阅读 6.3k
2 个回答

当然不需要提交,因为这些文件,可以通过 package.json 很方便再次下载。

如果你是 git 的话,可以在根目录上加一个 .gitignore 文件,内容:

# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp

# dependencies
/node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
testem.log
/typings

# e2e
/e2e/*.js
/e2e/*.map

#System Files
.DS_Store
Thumbs.db

楼上的回答是很精准的,pakcage.json中有记录依赖的,如果你说的用户是想运行这个网站的话,依赖当然要根据package.json中的记录自己下了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题