Adding javascript files (Waypoints)

Hey there @blitz!

First of all, please do a search before posting (I searched for “waypoints”). We’ve actually covered waypoints specifically before: Is Bower documentation needed? (Can I help?)

Anyways, there are a lot of ways to do it, but if you’re using waypoints on every page I would think you’d just want to include it in main.js, so here’s how I’d do that:

First, bower install waypoints --save
Then, Add waypoints overrides to the bower.json file because their main argument doesn’t include the jQuery version or the sticky that you want:

Then, run gulp and you should have your js compiled into in main.js now.
Finally, add your waypoints code either in the init or finalize anonymous functions in main.js and it should run on every page.

And just so you know, js does not need enqueuing if your scripts from bower are being piped into one of the files already in manifest.json, such as main.js. As soon as you make a new file (stick.js for example), you’ll need to enqueue that wherever you need it. In this case, I’d recommend my approach above. You can also check out my angular post for an example of some more working complex manifest and bower examples.

6 Likes