Grunt,NPM和Bower之间的区别(package.json vs bower.json) [英] Difference between Grunt, NPM and Bower ( package.json vs bower.json )

查看:146
本文介绍了Grunt,NPM和Bower之间的区别(package.json vs bower.json)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用npm和bower的新手,在emberjs中构建我的第一个应用:)。
我有一些使用rails的经验,所以我很熟悉文件的概念列出了依赖关系(比如bundler Gemfile)

问题:当我想添加一个包(并检查依赖到git中)时,它属于哪里 - 放入 package.json 或放入 bower.json



我收集,

运行 bower install 将获取该包并将其放入 / vendor 目录,

正在运行 npm install 它会将它读取并放到 / node_modules 目录中。

这个回答表示bower是用于前端, npm是用于后端的东西。

Ember-app-kit 好像从第一眼就坚持这个区别......但是对于启用某些功能给出两条明确的命令,所以我完全糊涂在这里。



直觉上,我猜测


  1. npm install --save-dev package-name 等价于将package-name添加到我的包中.json

  2. bower install --save package-name 可能与将包添加到我的 bower中相同。 json 并运行 bower install ?如果是这种情况,我应该什么时候明确地安装软件包,而不是将它们添加到管理的文件中依赖关系(除了全局安装命令行工具外)?

    解决方案

    2016年中更新 p>

    事情变化如此之快,以至于如果它迟到了2017年,这个答案可能不会是最新的!



    初学者在选择构建工具和工作流程时可能很快就会迷失方向,但2016年最新的版本根本不使用Bower,Grunt或Gulp!在Webpack的帮助下,您可以直接在NPM中完成所有工作!





    别误解我的意思,人们使用其他工作流程,我仍然在我的遗留项目中使用GULP(但是慢慢地从中移出),但这是如何在最好的公司完成的,在这个工作流程中工作的开发人员赚了很多钱!



    看看这个模板,它是一个非常新颖的设置,由最好的和最新的技术:
    https://github.com/coryhouse/react-slingshot




    • Webpack

    • NPM作为构建工具(不包含Gulp,Grunt或Bower)
    • li>
    • ESLint

    • 该列表很长。
      $ b $ b 您的问题: $ b p>当我想添加一个包(并检查依赖到git中)
      它属于哪里 - 进入package.json或进入bower.json




      • 现在一切都属于package.json


      • 构建所需的依赖关系在devDependencies中,即 npm install require-dir --save-dev (--save-dev通过向devDependencies添加条目来更新package.json)


      • 运行时应用程序所需的依赖项位于依赖项中,即 npm install lodash --save (--save更新您的包.json通过向依赖关系添加条目)




      如果是这种情况,我应该何时安装包显式地这样做,而不将它们添加到管理依赖关系的文件中(除了全局安装命令行工具外)?


      始终。只是因为舒适。当您添加一个标志( - save-dev - save )时,管理deps的文件(包。 json)自动更新。不要通过手动编辑依赖关系来浪费时间。 npm install --save-dev package-name 的快捷方式是 npm i -D package-name 以及 npm install --save package-name is npm i -S package-name


      I'm new to using npm and bower, building my first app in emberjs :).
      I do have a bit of experience with rails, so I'm familiar with the idea of files for listing dependencies (such as bundler Gemfile)

      Question: when I want to add a package (and check in the dependency into git), where does it belong - into package.json or into bower.json?

      From what I gather,
      running bower install will fetch the package and put it in /vendor directory,
      running npm install it will fetch it and put it into /node_modules directory.

      This SO answer says bower is for front-end and npm is for backend stuff.
      Ember-app-kit seems to adhere to this distinction from the first glance... But instructions in gruntfile for enabling some functionality give two explicit commands, so I'm totally confused here.

      Intuitively I would guess that

      1. npm install --save-dev package-name would be equivalent to adding the package-name to my package.json

      2. bower install --save package-name might be the same as adding the package to my bower.json and running bower install?

      If that is the case, when should I ever install packages explicitly like that without adding them to the file that manages dependencies (apart from installing command line tools globally)?

      解决方案

      Update for mid 2016:

      The things are changing so fast that if it's late 2017 this answer might not be up to date anymore!

      Beginners can quickly get lost in choice of build tools and workflows, but what's most up to date in 2016 is not using Bower, Grunt or Gulp at all! With help of Webpack you can do everything directly in NPM!

      Don't get me wrong people use other workflows and I still use GULP in my legacy project(but slowly moving out of it), but this is how it's done in the best companies and developers working in this workflow make a LOT of money!

      Look at this template it's a very up-to-date setup consisting of a mixture of the best and the latest technologies: https://github.com/coryhouse/react-slingshot

      • Webpack
      • NPM as a build tool (no Gulp, Grunt or Bower)
      • React with Redux
      • ESLint
      • the list is long. Go and explore!

      Your questions:

      When I want to add a package (and check in the dependency into git), where does it belong - into package.json or into bower.json

      • Everything belongs in package.json now

      • Dependencies required for build are in "devDependencies" i.e. npm install require-dir --save-dev (--save-dev updates your package.json by adding an entry to devDependencies)

      • Dependencies required for your application during runtime are in "dependencies" i.e. npm install lodash --save (--save updates your package.json by adding an entry to dependencies)

      If that is the case, when should I ever install packages explicitly like that without adding them to the file that manages dependencies (apart from installing command line tools globally)?

      Always. Just because of comfort. When you add a flag (--save-dev or --save) the file that manages deps (package.json) gets updated automatically. Don't waste time by editing dependencies in it manually. Shortcut for npm install --save-dev package-name is npm i -D package-name and shortcut for npm install --save package-name is npm i -S package-name

      这篇关于Grunt,NPM和Bower之间的区别(package.json vs bower.json)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆