您是否将Babel和Webpack放在devDependencies或Dependencies中?

我是npm的新手,并不真正了解依赖项与devDependencies的关系。 我知道对于测试库,他们应该进入开发人员,但是对于babel和webpack这样的东西呢? 它们是否也应该在dev中,因为它们仅用于将es6和JSX反编译为原始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"
  }
3个解决方案
38 votes

bundle.jswebpack软件包将进入devDependencies部分,因为在将代码转换和捆绑到bundle.js等文件中的普通javascript中时,将使用这些软件包。

在生产中,您将在bundle.js之外运行代码,生成/生成的代码将不再需要这些依赖项。

Zohaib Ijaz answered 2020-02-13T21:21:01Z
7 votes

尽管基本上每个人都说了些什么,但我还是要提个理智……这很简单:

您的项目将要由另一个项目devDependencies代替吗? 也就是您正在编写npm模块吗? 最终会出现在另一个项目package.json中吗?

没有?

然后将所有内容放入devDependencies

是?

  • devDependencies:您希望项目的下游使用者和项目开发人员安装的东西:
  • devDependencies:下游用户需要确保已安装的内容
  • devDependencies:下游用户将需要并且不需要单独安装的东西,因为当您devDependencies时,这些东西将与您的包装“捆绑在一起”。
  • devDependencies:拥有不错但没有的东西不会导致致命错误
  • devDependencies:仅在项目中使用的东西。

简而言之就是:模块不会神奇地得到不同的安装。 他们要么被安装,要么没有被安装。

airtonix answered 2020-02-13T21:22:06Z
0 votes

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"
Shubham Laad answered 2020-02-13T21:22:26Z
translate from https://stackoverflow.com:/questions/40143357/do-you-put-babel-and-webpack-in-devdependencies-or-dependencies