Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp uglify breaking angular application

When trying to use gulp-ugily with my angular application, it is breaking, even though I am running it through gulp-ngmin.

Here is the gulp file:

var gulp = require('gulp'),
    concat = require('gulp-concat'),
    ngmin = require('gulp-ngmin'),
    uglify = require('gulp-uglify');

gulp.task('compress', function() {
    gulp.src('client/js/source/*.js')
        .pipe(concat('app.js'))
        .pipe(ngmin())
        .pipe(uglify())
        .pipe(gulp.dest('client/js'));
});
like image 441
Justin Avatar asked Jun 26 '14 19:06

Justin


2 Answers

It helps to disable the mangle option in uglify, for it's messing with all the injection stuff and naming.

.pipe(uglify({ mangle: false }))
like image 107
beauXjames Avatar answered Oct 16 '22 17:10

beauXjames


Maybe answering this for future users, as it seems the post is old.

Use ng-annotate to fix AngularJS problems when uglifying. Install it as any other library:

npm install gulp-ng-annotate --save-dev

And then use this in your gulpfile.js:

var gulp = require('gulp')
var concat = require('gulp-concat')
var uglify = require('gulp-uglify')
var ngAnnotate = require('gulp-ng-annotate')

gulp.task('js', function () {
  gulp.src(['src/**/module.js', 'src/**/*.js'])
    .pipe(concat('app.js'))
    .pipe(ngAnnotate())
    .pipe(uglify())
    .pipe(gulp.dest('.'))
})

Hope this helped!

Source: https://medium.com/@dickeyxxx/best-practices-for-building-angular-js-apps-266c1a4a6917

like image 25
Daniel Ferraz Avatar answered Oct 16 '22 17:10

Daniel Ferraz