Leah Sapan
Leah Sapan

Reputation: 3791

Combine multiple javascript files with bower

I'm looking into using Bower with my project (more specifically, django-bower), and I was curious if bower has the ability to combine multiple javascript files into one file when pushing to production.

In other words it would take:

and produce one file that the user loads: everything.js

In reality we have upwards of 20-30 js files, which is why this would be incredibly helpful.

Upvotes: 3

Views: 2720

Answers (2)

Preston S
Preston S

Reputation: 2771

Use Browserify. It takes your Node requires and compiles them into a single JS file that can be included in your HTML. Ex main.js:

var JQuery = require('jquery');
var Angular = require('Angular');
require('./something_else');
require('./another_thing');

Browserify your dependency chain...

browserify main.js > compiled.js

Include in your HTML

<html>
  <head>
    <script type="text/javascript" src="compiled.js"></script>
  </head>
</html>

Upvotes: 2

Dziad Borowy
Dziad Borowy

Reputation: 12579

Bower is a package manager. I think what you're looking for is Grunt.

See how to minify multiple js files using grunt.

Upvotes: 4

Related Questions