How to stop Grunt.js from minifying my Yeoman webapp How to stop Grunt.js from minifying my Yeoman webapp node.js node.js

How to stop Grunt.js from minifying my Yeoman webapp


I had the same desire to modify the Yeoman webapp build so that the results (javascript, css, and index.html) were not minified. My approach was to try and modify only the Gruntfile. I wanted to avoid making any changes directly by hand to the index.html structure already provided by Yeoman. And I wanted to avoid making any post-build manual changes to the resultant build files (too tedious). Just wanted to build and go - no minification.

Here's what I've come up with, in case it might be helpful to others. I narrowed this down to making two changes to the Gruntfile, as follows.

First, I modified the UseminPrepare configuration to concatenate but not uglify js files or minify css files:

In UseminPrepare, I changed this:

js: ['concat', 'uglifyjs'],css: ['cssmin']

To this:

js: ['concat'],css: ['cssmin']

Second, I modified the build task series by eliminating the 'uglify' and 'htmlmin' tasks, but somewhat paradoxically you must leave the 'UseminPrepare' and 'usemin' tasks in the series. By doing so, you leverage usemin for concatenation and copying but avoid having it minify.

Change the build task by commenting out 'uglify' and 'htmlmin' (don't forget to be sure the usemin task, now last in the series, does not end with a comma :)):

grunt.registerTask('build', [ 'clean:dist', 'bowerInstall', 'useminPrepare', 'concurrent:dist', 'autoprefixer', 'concat', 'ngmin', 'copy:dist', 'cdnify', 'cssmin', //'uglify', 'rev', 'usemin' //'htmlmin']);

Now simply run grunt build and it's done. Worked for me.

I hope that might be helpful to someone else.


If you remove the htmlmin task, it should stop minifying the HTML. If you want to stop minifying other things, you can remove the other *min tasks as well. All you need to remove them from is the register tasks at the bottom. However, if you don't plan on using them, it'd make sense to remove the accompanying blocks as well.


If you have output style set as compressed, you have to remove that like

dist:  options:    **outputStyle: 'compressed'**    debugInfo: false    noLineComments: true

To

dist:  options:    **#outputStyle: 'compressed'** #remove it    debugInfo: false    noLineComments: true