Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symlink or copy files out of bower component

I need a way to define the files that I need from a bower component. In bower.json in the component the files I need aren't specified in the main setting. I would love a way to symlink or copy the files into another directory assets directory from bower. I use Grunt and I haven't found anything that can help. I'd love some way I could define all the files via json.

Apologies if this isn't entirely stackoverflow worthy but I'm really desperate to find something that exists and not reinvent the wheel.

I found this code here and I don't know how to use it. This would be ideal.

"dependencies": {
  "font-awesome": ">= 3.2.1"
},
"overrides": {
  "font-awesome": {
    "main": [
      "css/font-awesome.min.css",
      "font/FontAwesome.otf",
      "font/fontawesome-webfont.eot",
      "font/fontawesome-webfont.svg",
      "font/fontawesome-webfont.ttf",
      "font/fontawesome-webfont.woff"
    ]
  }
}
like image 669
ThomasReggi Avatar asked Oct 08 '13 15:10

ThomasReggi


3 Answers

What I personally do & recommend is create a .bowerrc file in your project root with postinstallinstructions to move assets:

{
  "scripts": {
    "postinstall": "mv ./bower_components/path/to/my.js ./path/to/ideal/location/my.js"
  }
}
like image 105
Eric Avatar answered Oct 20 '22 22:10

Eric


Have a look at grunt-bower-task. The documentation suggests this, under advanced usage:

At this point of time "Bower package" = "its git repository". It means that package includes tests, licenses, etc. Bower's community actively discusses this issue (GitHub issues #46,#88, on Google Groups) That's why you can find such tools like blittle/bower-installer which inspired this project.

Okay, if you want more than "main" files in ./lib directory then put "exportsOverride" section into your bower.json:

{
  "name": "simple-bower",
  "version": "0.0.0",
  "dependencies": {
    "jquery": "~1.8.3",
    "bootstrap-sass": "*",
    "requirejs": "*"
  },
  "exportsOverride": {
    "bootstrap-sass": {
      "js": "js/*.js",
      "scss": "lib/*.scss",
      "img": "img/*.png"
    },
    "requirejs": {
      "js": "require.js"
    }
  }
}

grunt-bower-task will do the rest.

like image 31
Ben Avatar answered Oct 20 '22 22:10

Ben


I've been using bower-installer with success, which might be of interest to those not using Grunt.

Font Awesome needed extra wrestling because the CSS file uses relative paths (e.g. ../fonts/).

{
  "dependencies": {
    ...
  },
  "install": {
    "path": "webroot/components",
    "sources": {
      "font-awesome": {
        "mapping": [
          {"bower_components/font-awesome/css/font-awesome.css": "font-awesome.css"},
          {"bower_components/font-awesome/fonts/fontawesome-webfont.eot": "../fonts/fontawesome-webfont.eot"},
          {"bower_components/font-awesome/fonts/fontawesome-webfont.svg": "../fonts/fontawesome-webfont.svg"},
          {"bower_components/font-awesome/fonts/fontawesome-webfont.ttf": "../fonts/fontawesome-webfont.ttf"},
          {"bower_components/font-awesome/fonts/fontawesome-webfont.woff": "../fonts/fontawesome-webfont.woff"},
          {"bower_components/font-awesome/fonts/FontAwesome.otf": "../fonts/FontAwesome.otf"}
        ]
      }
    }
  }
}
like image 2
deizel Avatar answered Oct 21 '22 00:10

deizel