简体   繁体   中英

Should vendor assets be included in version control with bower + rails?

I've started to use bower-rails to manage css/js assets in my rails projects. By default the dependences are being installed in vendor/assets/bower_components . The problem is that bower copies the whole packages, including sources, examples, licenses, etc.
I don't have problem to get rid of all those files, but I'm wondering if is necessary to include even the important files, as I think it should be the programmer's responsibility to load those dependences in the computer where is loading the project(maybe with grunt?), besides is supposed you should not touch the vendor packages as they are not your responsibility(regarding all those crappy files I want to delete).
My point is: Is there any kind of "best practice" related with bower packages and version control?

I recently used bower-rails for the first time and had Git ignore the vendor/assets/bower_components directory to good effect.

If you choose to have Git ignore bower_assets , you SHOULD specify a known good version of each library in bower.json instead of using latest to avoid version conflicts.

I'm using bower and bower-installer in my Rails 4.2.x app, without using any gems for javascript dependencies. I'm still using the asset pipeline.

I added vendor/assets/bower_components to my .gitignore file. I use bower-installer to copy just what I need to vendor/assets/{javascripts,stylesheets} , which are in source control.

I think that this gives me the best of both worlds: version control of JS libraries so updates are relatively easy, but no chance of a production deploy failing because someone removed 'leftpad' from the node repo.

Here's a trimmed-down version of my bower.json file (in source control). Note that jquery-form is not in the bower repo, so I included the path to the download file.

{
  "name": "icots",
  "main": "",
  "private": true,
  "ignore": [
    "**/.*",
    "bower_components",
    "vendor/assets/bower_components",
    "lib"
  ],
  "dependencies": {
    "jquery": "^3.1.1",
    "jquery-ui": "^1.12.1",
    "jquery.form": "http://malsup.github.io/min/jquery.form.min.js"
  },
  "install": {
    "path": {
      "js": "vendor/assets/javascripts",
      "css": "vendor/assets/stylesheets",
      "/[sc|le]ss$/": "vendor/assets/stylesheets"
    },
    "sources": {
      "jquery": "vendor/assets/bower_components/jquery/dist/jquery.min.js",
      "jquery-ui": "vendor/assets/bower_components/jquery-ui/jquery-ui.min.js",
      "jquery-form": "vendor/assets/bower_components/jquery.form/index.js"
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM