A
A
Anton2015-11-01 18:57:55
Angular
Anton, 2015-11-01 18:57:55

How to properly minify an AngularJs application?

There is an application written in angular, it is not written very well, as it usually happens, I decided to first bring it to a normal structure - move the controllers and everything that comes with them into separate folders, and manually inject dependencies through SomeController.$inject = ['foo', 'bar'];
After this mind-blowing fun, I decided compile this case into one file using gulp , here is my gulp file:

gulp.task('scripts', function() {
    return gulp.src(['public/assets/**/*.js', '!public/assets/vendor/**/*.js'])
        .pipe(cached('scripts'))     
        .pipe(jshint())                
        .pipe(header('(function () {')) 
        .pipe(footer('})();'))        
        .pipe(remember('scripts'))    
        .pipe(ngmin())
        .pipe(concat('app.js'))       
        .pipe(gulp.dest('public/'));

ngAnnotate did not connect, because I injected everything manually, but I rightly assumed that ngmin () will give out the files in the correct order, but he connected the file with the module fourth or fifth, after I manually moved it to the beginning, there were still errors ...
What do I do isn't it, sir?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-11-01
Protko @Fesor

it to the normal structure - move the controllers and everything attached to them into separate folders

This step has a very dubious benefit, but not the point.
ngmin does exactly the same as ngAnnotate only worse slower and generally deprecated.
In general, to put it mildly, angular does not matter in what order what is declared there, you can certainly get problems if the providers are at the very bottom ... but this is a very rare case. Everything is broken by the system of angular modules. As a last resort, there is gulp-order.
If you are using getters for modules and not a variable:
// плохо
var app = angular.module('app', deps);
// ...
app.service('foo', FooService);

// хорошо
angular.module('app').service('foo', FooService);

then the angular, again, will destroy everything itself due to the lazy initialization of the modules.
Which mistakes? You didn't bring them. They don't know how to guess.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question