我是npm的新手,并不真正了解应该依赖于devDependencies的内容。我知道,对于测试库,他们应该进入dev,但对于像babel和webpack这样的东西呢?他们是不是也应该在dev中,因为他们只是用来将es6和JSX转换成vanilla JS?我的理解是,当你部署到heroku时,它已经使用必要的库进行转换,所以不需要在生产中托管它们吗?
"dependencies": {
"babel-core": "^6.7.7",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-plugin-transform-react-display-name": "^6.5.0",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"bootstrap": "^3.3.7",
"css-loader": "^0.23.1",
"es6-promise": "^3.2.1",
"eslint": "^2.9.0",
"eslint-plugin-babel": "^3.2.0",
"eslint-plugin-react": "^5.0.1",
"express": "^4.13.4",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"lodash": "^4.15.0",
"react": "^15.0.2",
"react-addons-css-transition-group": "^15.0.2",
"react-dom": "^15.0.2",
"react-redux": "^4.4.5",
"react-transform-catch-errors": "^1.0.2",
"react-transform-hmr": "^1.0.4",
"redbox-react": "^1.2.3",
"redux": "^3.5.2",
"redux-form": "^6.1.0",
"rimraf": "^2.5.2",
"style-loader": "^0.13.1",
"webpack-dev-middleware": "^1.6.1",
"webpack-hot-middleware": "^2.10.0"
},
"devDependencies": {
"babel-register": "^6.9.0",
"chai": "^3.5.0",
"mocha": "^2.5.3",
"sinon": "^1.17.4",
"webpack": "^1.13.2"
}
答案 0 :(得分:31)
babel
和webpack
包将进入devDependencies
部分,因为在bundle.js
中将代码转换并捆绑到vanilla javascript时会使用这些包&安培;等文件。
在生产中,您将从bundle.js
构建/生成的代码中运行代码,不再需要这些依赖项。
答案 1 :(得分:2)
尽管基本上每个人都说些什么,但我还是要提个理智……这确实很简单:
您的项目会被另一个项目npm install
吗?也就是您正在编写npm模块吗?会结束于另一个项目package.json
吗?
否?
然后将所有内容放入dependancies
。
是吗?
dependancies
:您希望下游消费者和项目的项目开发人员安装的东西:peerDependancies
:下游用户需要进行的操作,以确保他们已安装bundleDependancies
:您的下游用户将需要并且不需要单独安装的东西,因为当您npm publish
时,这些东西将与您的软件包捆绑在一起。optionalDependancies
:拥有美好的事物但缺少不会导致致命错误devDependancies
:仅在处理项目时使用的东西。optionalDependancies
:拥有美好的事物但缺少不会导致致命错误它的不足之处是:模块的安装方式没有不同。他们要么被安装,要么没有被安装。
答案 2 :(得分:0)
Dev依赖是仅用于开发服务器的,这些是devDepedency: 所有未在源代码中使用或导入的包都是devDependencies
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.4.0",
"node-sass": "^4.8.3",
"optimize-css-assets-webpack-plugin": "^4.0.0",
"prop-types": "^15.6.1",
"sass-loader": "^7.0.1",
"style-loader": "^0.21.0",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^4.6.0",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.9"