-->

Bower.json install only single file

2019-08-03 17:02发布

问题:

I am a bower newbie. How can I download only a single file from GitHub instead of the entire set of files? I just want the latest fuelux.min.js file from here (https://raw.githubusercontent.com/ExactTarget/fuelux/master/dist/js/fuelux.min.js) and I want to put it in my plugins directory.

{
  "name": "my app",
  "version": "1.0",
  "dependencies": {
    "angular-local-storage": "latest",
    "fuelux":"latest"
    },
  "install" : {
    "path" : {
      "js": "plugins"
      }
  }
}

回答1:

The idea of bower is that you include the entire published contents of the repository/package which is then installed by a developer through bower. You use your build system (grunt, broccoli, etc) to pick any files from that which need to be included in your own distribution.

If for some reason you really only want that single file you'll just have to include it in your application manually.



回答2:

I agree with the answer provided by @Leeft. Should the circumstance arise when you do only need one file you can reference the Raw file listed on github in your install.

bower install https://raw.githubusercontent.com/chrishunt/retinajs/master/src/retina.js --save

This will include the dependency in your bower.json file

"dependencies": {
    "retina": "https://raw.githubusercontent.com/chrishunt/retinajs/master/src/retina.js"
}


回答3:

If you use wiredep with bower, you can add an overrides section to your package's bower.json, like:

"overrides": {
  "fuelux": {
    "main": [
      "dist/js/fuelux.min.js"
    ]
  }
}


回答4:

I agree with simple the one thing I don't enjoy about NPM and Bower is that they bloat the file-size on every project, sometimes when there's no need to.

Take a look at this NPM package that allows to install specific files and not the entire repo:

https://github.com/blittle/bower-installer