user3146472
user3146472

Reputation: 403

How to compile multiple angularjs files into single application file

I recently started using angularjs and at the moment I am working on developing someone else's code. The whole application is divided into multiple files, but at the end they are used from single application.js file.

I have a file looking like this:

//= require (some path)
//= require (some path)
angular.element(document).ready(function () {
    angular
        .bootstrap(document, [
            (multiple routes)
        ]);
});

Seems like I need to compile this file to generate a new, bigger file for whole app. I can't figure how, though.

Upvotes: 0

Views: 4116

Answers (2)

Charles
Charles

Reputation: 534

I wanted to just make this a comment to your original post, but it was too long. This isn't a definitive answer, so I apologize. Based on another post, (Google Closure Compiler Includes) I suspect they may have been using Google's Closure compiler, and using the require statements to trigger the Closure compiler's dependency analysis.

Apparently the compiler can translate the RequireJS 'require' statements into goog.require statements to establish ordering dependencies between the javascript files. So you may want to look at the monolithic file and see if there's any signs it went through the Closure compiler.

Upvotes: 0

ngasull
ngasull

Reputation: 4216

There are multiple ways to do this, you could pick an existing library like:

  • Uglify: traditional way to concatenate, minify and "uglify" JS sources into a single ".min.js" file. This is useful if you want to concatenate all js files in a whole directory structure more than using explicit relative requires.

  • Browserify: uses CommonJS's require to generate a single file wisely resolving dependencies. Looks more like the way you are looking to implement your app! Note that the require calls are resolved server (NodeJs) side.

  • RequireJS: specific require for browsers, means that your code would only run client-side.

Upvotes: 1

Related Questions