Skip to content Skip to sidebar Skip to footer

Concatenate Javascript In Anonymous Function With Gulp

I use gulp to concat my scripts into one file. Before concatenation I've split up my .js files into seperate files. So I've got app.js where I declare my angular app and some other

Solution 1:

If you're not using CommonJS or AMD modules and just concatenating scripts then just make sure each concatenated script gets the module it needs in it's own scope.

(function() {

    // Declare appvar app = angular.module('Application', ['ngRoute']);

    // Do stuff with variable app in scope.

})();

Now in your routes.js

(function() {

    // Grab the already created module for use// in this scope.var app = angular.module('Application');

    app.config([
        '$locationProvider', 
        '$routeProvider',
        function($locationProvider, $routeProvider) {

            $locationProvider.html5Mode = true;

            $routeProvider.when('/', {
                controller : 'MyCtrl',
                templateUrl : 'index.html'
            });
        }
    ]);
})() 

Post a Comment for "Concatenate Javascript In Anonymous Function With Gulp"