简体   繁体   English

你把Babel和Webpack放在devDependencies或Dependencies中吗?

[英]Do you put Babel and Webpack in devDependencies or Dependencies?

I'm new to npm and don't really understand what should go into dependencies vs. devDependencies. 我是npm的新手,并不真正了解应该依赖于devDependencies的内容。 I know that for testing libraries they should go into dev, but how about for things like babel and webpack? 我知道,对于测试库,他们应该进入dev,但对于像babel和webpack这样的东西呢? Should they be in dev too, because they're only used to transcompile es6 and JSX into vanilla JS? 他们是不是也应该在dev中,因为他们只是用来将es6和JSX转换成vanilla JS? My understanding is that when you deploy to heroku, it do the transcompiliation with the necessary libraries already, so there's no need to host them on production? 我的理解是,当你部署到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"
  }

The babel and webpack packages will go into the devDependencies section because these packages are used in when transpiling and bundle-ing your code into vanilla javascript in the bundle.js & etc file(s). babelwebpack包将进入devDependencies部分,因为这些包在将代码转换并捆绑到bundle.js &etc文件中的vanilla javascript时使用。

In production you will run your code off the bundle.js build/generated code will not require these dependencies anymore. 在生产中,您将从bundle.js构建/生成的代码中运行代码,不再需要这些依赖项。

Despite what basically everyone says, I'm going to offer a piece of sanity... it's really quite simple: 尽管基本上每个人都说,我会提供一个理智......它真的很简单:

Is your project going to be npm install ed by another project? 您的项目是否会由另一个项目npm install aka are you authoring a npm module? 你是在创作一个npm模块吗? will it end up in another projects package.json ? 它会在另一个项目package.json结束吗?

No? 没有?

Then put everything in dependencies . 然后将所有内容放在dependencies

Yes? 是?

  • dependencies : Things you want downstream consumers and project developers of your project to have installed: dependencies :您希望项目的下游消费者和项目开发人员安装的内容:
  • peerDependencies : Things your downstream users need to make sure they have installed peerDependencies :下游用户确保已安装的东西
  • bundleDependencies : Things your downstream users will need, and won't need to install separately because when you npm publish , these will be "bundled" with your package. bundleDependencies :下游用户需要的东西,不需要单独安装,因为当你npm publish ,这些将与你的软件包“捆绑”。
  • optionalDependencies : Things that are nice to have but the absence of will not cause fatal error optionalDependencies :好的东西,但没有不会导致致命的错误
  • devDependencies : things only used while working on your project. devDependencies :仅在处理项目时使用的东西。
  • optionalDependencies : Things that are nice to have but the absence of will not cause fatal error optionalDependencies :好的东西,但没有不会导致致命的错误

The short of it is this: modules do not magically get installed differently. 缺点是:模块不会以不同的方式神奇地安装。 They either get installed or they do not. 他们要么安装,要么不安装。

Dev dependency is which only use for the development server, these are devDepedency: All the packages which are not using in source code or imported are devDependencies 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于es6依赖的webpack babel加载器 - webpack babel loaders for es6 dependencies eslint 'html-webpack-plugin' 应该列在项目的依赖中,而不是 devDependencies 中。 (导入/无外部依赖项) - eslint 'html-webpack-plugin' should be listed in the project's dependencies, not devDependencies. (import/no-extraneous-dependencies) 在构建脚本中使用 Babel 时,如何为生产部署设置依赖项? - How do you setup dependencies for production deploy when Babel is used in build script? 将 devDependencies 和依赖项与 yarn 一起安装 - Install devDependencies and dependencies together with yarn Webpack Babel 6 - Webpack Babel 6 Webpack + Babel 正在转译 Webpack 加载器,我该如何防止? - Webpack + Babel is transpiling Webpack loaders, how do I prevent this? Webpack 和 Babel “你可能需要一个合适的加载器来处理这种文件类型” - "You may need an appropriate loader to handle this file type" with Webpack and Babel Webpack和Babel的“您可能需要适当的加载器来处理此文件类型” - “You may need an appropriate loader to handle this file type” with Webpack and Babel eslint 应该列在项目的依赖项中,而不是 devDependencies - eslint should be listed in the project's dependencies, not devDependencies Webpack 4 + Babel 7.4.0 + Babel Polyfill - Webpack 4 + Babel 7.4.0 + Babel Polyfill
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM