How to build release with minification


Hi, I just run the command ionic build android --release which output the file android-release-unsigned.apk. I opened this up (using 7zip) and as far as I can tell, at least my own code does not appear to be minified (looking into main.js), it has all the comments, spaces and full variable names etc in there.

Should this be part of the stock build process? ionic --version gives me 2.2.1.

Thanks in advance!


You need to run the command with --prod.
ionic build android --prod --release


It’s not cordova’s job to do that. Use a build tool like weback or gulp. Gulp is pretty simple to setup. You can start with gulp uglify plugin.

var gulp = require('gulp');
var gutil = require('gulp-util');
// Reused
var concat = require('gulp-concat');

var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var stripDebug = require('gulp-strip-debug');

gulp.task('js', function(){
  return gulp.src("arrayOfFilePathsToYourJSFiles")
  .pipe(uglify({mangle: false}))


Thanks that did the trick… Interesting the .map file is included. I wonder if that is needed, and if that can be removed.


.map file should be removed for production, as it is only needed for development purposes.