mquandalle/meteor-bower

Bower packages loading order

Closed this issue · 6 comments

Not sure if this is answered somewhere, but I'm new to MeteorJS. How can I get bower packages to load before the JS in my client directory?

I am trying to use a jQuery plugin (velocity) but it's being loaded as a bower package after I call the plugin in a script in client directory.

I want my bower scripts to load before client directory scripts.

Same here, bower adds files after client directory's javascripts, so no way to use any plugin(?)

Rendered HTML:

...
  <script type="text/javascript" src="/client/templates/invoice.jade.js?23a13d4931d382f92182d4fedc81afc4a26f5294"></script>
  <script type="text/javascript" src="/client/templates/invoice.js?7ec4905a0aa7b893ff6d513029c2c8b49bb706f9"></script>
  <script type="text/javascript" src="/packages/bower/jquery.payment/lib/jquery.payment.js?c5d73e3f2f3c4438de3a2cb799920700eb6b2b80"></script>
  <script type="text/javascript" src="/router.js?a92db69199582d952b2ea7628c93aa2d7e817b87"></script>

Clean import is only possible with a meteor package at moment.

@gbisheimer do you know how this might be fixed?

Reading this I found the same issue reported here. Based on the last comment by @glasser, I moved the bower.json file to the /lib folder and run meteor, and all my bower packages got moved up, but they are still below the template's code in my application.

This is what it looks like right now:

  <script type="text/javascript" src="/client/views/home/template.home.js?082b2612b4eb2eb7106a8e48f87aa96c078d6977"></script>
  <script type="text/javascript" src="/client/views/kanban/template.board.js?2e0a37afb16faaf0bffd4bda27e5186df64e1806"></script>
  <script type="text/javascript" src="/client/views/kanban/template.boards.js?edfc6a308c1e0a8f11546720b4f4ce2f98156373"></script>
  <script type="text/javascript" src="/client/views/kanban/template.column.js?2197e008b224c7f7058f7bbbe44416551b99e790"></script>
  <script type="text/javascript" src="/client/views/kanban/template.task.js?04abb726824484515b034e506eb4af5846001ee1"></script>
  <script type="text/javascript" src="/client/views/navigation/template.navigation.js?1b2a98b936fe4669073c4e53f9f60e0b2335411d"></script>
  <script type="text/javascript" src="/client/views/polymer_test/template.polymer_test.js?5a3a3f45d348f54f3fe6a2cbea1cc3456f218f30"></script>
  <script type="text/javascript" src="/client/views/template.layout.js?8696380f16cc8b22608bbaf415b545156475b62a"></script>
  <script type="text/javascript" src="/client/views/template.main.js?702eb0b67f2a7fe67f3ed93d3f70d1535fede05a"></script>
  <!-- meteor-bower inserted lines -->
  <script type="text/javascript" src="/packages/bower/select2/select2.js?abe717163806ed132d2784d848568d39d3e4bc8e"></script>
  <script type="text/javascript" src="/packages/bower/webcomponentsjs/webcomponents.js?6eb551c19db685b5d2cda035252cd344fa666575"></script>
  <!-- meteor-bower inserted lines -->
  <script type="text/javascript" src="/client/views/clocks/clock.js?6c91801e25891d9caa6f7400436c6741fa7607e8"></script>
  <script type="text/javascript" src="/client/views/home/home.js?cb56c918f2603ea97afd4443ea6b4ecf128fa905"></script>
  <script type="text/javascript" src="/client/views/kanban/board.js?051fd3bf0a211252c8c7d22684d5c57a160bf17a"></script>
  <script type="text/javascript" src="/client/views/kanban/boards.js?3a97180cf46bfdf4f0137acfd30051b65f3360a3"></script>
  <script type="text/javascript" src="/client/views/kanban/column.js?8a896d175cc077e43a0532a9f39e723821f40f94"></script>
  <script type="text/javascript" src="/client/views/kanban/task.js?f7b2d7c65b4fdb478eccf67d71a3f79ddc6b02ca"></script>
  <script type="text/javascript" src="/client/views/navigation/navigation.js?2a3453bba5b8f7e5a39caf4f0fb6016f1b588104"></script>
  <script type="text/javascript" src="/client/router/routes.js?f0591673c9e52425e0bfe45a6d098a3c538ac8aa"></script>
  <script type="text/javascript" src="/collections/collections.js?5369c93648c23aca212890bf94e744b11aece267"></script>

Before the modification those lines where at bottom.

As bower.json file is located on the root path, it get's parsed last (because of meteor's file ordering rules). AFAIK, there is no way to specify the file load order in meteor right now, but to follow the this rules

Don't know how to solve this yet.

I realized that template.something are generated by meteor to handle template rendering but they don't have application logic. So this change should allow to load bower packages before any other application logic, but always having in mind meteor's file ordering rules.

Thanks @gbisheimer! I tried adding isTemplate: true to

https://github.com/mquandalle/meteor-bower/blob/master/plugin/handler.js#L173

as is done in core:

https://github.com/meteor/meteor/blob/devel/packages/templating/plugin/compile-templates.js#L47

but that had no effect. Moving the location of bower.json did fix it, reproduction here:

https://github.com/lorensr/bower-load-order

The recommendation of the bower directory is in case they have a file in lib that comes before bower.json in alphabetical order (load order).