When I start a new Rails project, it gives me a template with a few different files for packages: Gemfile, package.json, and yarn.lock. I'm trying to understand if all three of these packages work together, or if I'm supposed to choose one. For example, in my Gemfile, I can add 'jquery-rails' but is this the same as installing jQuery to my package.json file? I'm having trouble understanding the difference between running bundle install and npm install.
Thanks.
In short it looks like this:
In Ruby, the bundler analyzes the list of libraries (gems) specified in the Gemfile, builds a dependency tree and fixes it in Gemfile.lock, downloads gems from different sources
In JS, various managers do the same: npm, yarn, bower, etc. By default Rails use yarn. They download all libraries to node_modules folder
package.json is analogue of Gemfile (but more advanced, for example you can define command line scripts there). yarn.lock is analogue of Gemfile.lock
Thus, bundler for Ruby and yarn / npm for JS libraries
Gemfile is to manage ruby gems, while package.json and yarn.lock for js packages.
The good thing about installing jQuery via jquery-rails is that will allow you to easily integrate jQuery into a Rails project, regardless what asset manager you're using it.
On the other hand, installing jQuery using npm/yarn allows you to upgrade the package directly from the original repo, without having an intermediary (jquery-rails in this case) that eventually could have the gem unattended (as now that they're using jquery 3.6.0 while the last one is 3.6.1).
Personally, I'd choose the 2nd option, mostly because in general is a good practice to have these js/ruby worlds working separately, but the other reason is because any other js library you eventually will need it, probably will follow the same steps as installing jQuery, so it's not really a big deal integrating it with Rails in this way.
I'm installing plugins using bower, but bower only downloads Footable v2.0.1, not the latest release of v2.0.1.5.
I've tried:
bower install --save-dev footable
bower install --save-dev footable#2.0.1.x
Both these download v2.0.1, I want the latest tagged release of v2 (v2.0.1.5).
Using #2.0.1.x also gave the error "ENORESTARGET: Tag/Branch 2.0.1.x does not exist".
Bower package versions should follow semantic versioning.
In short, a valid semantic version is in the form of MAJOR.MINOR.PATCH.
2.0.1.5, for example, is not a valid semantic version.
You can get a list of available versions for a package by running the following command:
bower info footable
For footable you the results are:
Available versions:
- 2.0.1
- 2.0.0
- 0.5.0
- 0.1.0
I have package bootstrap-calendar
In bower.json it is version 0.2.0-RC and I even updated it to 0.2.0. But no matter what when you run
$> bower install bootstrap-calendar
it attempts to install version 0.0.9 which is earliest version. I cleaned cache but no success. What can I do that on bower install command latest package would be installed?
I don't think this is anything you are doing incorrectly. The package installs for me as 0.0.9 and the js file is listed as 0.1. I think the package is just not correct and needs to be mentioned on the issues section of Github, which I did.
I wanted to install the backbone.routefilter plugin via Bower. It looks like there are 2 projects with that same name. http://sindresorhus.com/bower-components/#!/search/routefilter.
When I try to bower install backbone.routefilter#0.2.0 it tries to install 0.2.0 version from wanderer I want the latest from boazsender. Is there anyway to tell bower which repo to use?
That one seems to be wrongly registered. Use the correct one instead:
bower install backbone.routefilter
I was wondering if Bower will install the dependencies of the component I'm installing. Lets say I install a component which requires jQuery. Will Bower also install jQuery?
Bower will install the jQuery dependency for you if the component you installed have a bower.json with jQuery defined as a dependency.