Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

JS dependency manager

I'm working on JS app and I use npm package manager. The problem is that I need to include Bootstrap JS and its dependency - jQuery. I don't want to include it right into html, I use Grunt for minification, etc. How can I require another js file on client-side in my main.js file? I tried grunt-browserify, but it didn't work as I expected - it loaded Bootstrap first, not jQuery.

1 Answer

If you're using Browserify, then you would just put the require statement for jQuery before the one for Bootstrap:

window.$ = window.jQuery = require('jquery')
require('bootstrap');

You'll note that this is essentially putting jQuery in the global scope, which is how it was designed to work, and Bootstrap is built on it.

Thank you for answer. Now, it works. I was missing that "window.".