Code breaks after using gulp-uglify

Hi guys, I’m just new to Ionicframework and new to using gulp. I am currently setting up my workflow and I use gulp-uglify to minify my app files. After using it the code breaks so I checked on the console and got this error.

Uncaught Error: [$injector:modulerr] Failed to instantiate module ebhealth due to: Error: [$injector:unpr] Unknown provider: t

I am using this gulp function to basically gather all js file from a specified location, concatenate them to all.js then uglify/minify.

gulp.task('app-scripts', function(){  
  return gulp.src(paths.scripts)
    .pipe(concat('all.js'))
    .pipe(uglify())
    .pipe(gulp.dest('www/app-dist/'));
});

After executing this command, I checked the all.js and indeed it looks minified and uglified but when I refresh the browser it throws an error. What am I doing wrong?

Take a look at this:
https://docs.angularjs.org/tutorial/step_05#a-note-on-minification

And then add this to your workflow:
https://www.npmjs.com/package/gulp-ng-annotate

3 Likes

First of all, sorry for the delayed response. I got so busy this weekend and wasn’t able to answer back. Anyways… Thanks for sharing mate! I knew I was doing something wrong. I’m just new with angular and ionic so I didn’t know some of the bad practices that I might have been doing. I’ve also added the “gulp-ng-annotate” to my workflow and I confirm it to be a working solution. Thanks again :wink:

Use Mangle attribute to false for uglify when you are using gulp. It will resolve your problem

.pipe(uglify({mangle: false}))