Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right way to install and use bower in Meteor?

Tags:

npm

bower

meteor

In a meteor project, I want to pull a few frontend packages. bower can pull many frontend dependencies which are not yet available using meteor add. In many cases, when the meteor packages are available, their versions are lagging behind the official ones, sometimes too behind to consider.

Being a bit of a Meteor newb I've tried to install bower (the most recent meteor bower package I could find):

$ meteor add bozhao:bower

but then, when I run the meteor server it crashes:

W20160110-15:37:57.997(2)? (STDERR) /Users/igal/.meteor/packages/meteor-tool/.1.1.10.7bj3ks++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20160110-15:37:57.998(2)? (STDERR)                         throw(ex);
W20160110-15:37:57.998(2)? (STDERR)                               ^
W20160110-15:37:57.998(2)? (STDERR) ReferenceError: window is not defined
W20160110-15:37:57.998(2)? (STDERR)     at bower_components/leaflet/dist/leaflet-src.js:526:1

Question is: What's the best strategy to install bower and use it in a meteor project? An acceptable answer may show the flow for correctly installing bower, then the leaflet package and it's leaflet.markercluster extension

Sep 27th 2016 edit

The meteor community switched to npm, thus using bower is no longer required. Simply do npm install <package> and import <package> in your client-side code, and you can start using the component!

like image 391
tivoni Avatar asked Jan 10 '16 13:01

tivoni


1 Answers

meteor search bower turns up a few hits, which I haven't taken the time to compare in any depth. I went with mquandalle:bower as I found it recommended here. Perusing the doc, here is what worked for me:

npm install -g bower                # If not already done
meteor add mquandalle:bower
echo '{ "directory": ".meteor/local/bower" }' > .bowerrc    # If you use bower install --save

Then create a bower.json file at the top of the project tree that reads like this:

{
  "name": "MyApp",
  "version": "0.0.1",
  "dependencies": {
    "leaflet": ">0",
    "leaflet.markercluster": ">0"
  },
  "private": true
}

Re-run your app with meteor run and presto, the stylesheets and JavaScript of your modules are embedded into your page without even having to edit the <head>.

like image 112
DomQ Avatar answered Sep 28 '22 03:09

DomQ