Home » Nodejs » How to stop Grunt.js from minifying my Yeoman webapp

How to stop Grunt.js from minifying my Yeoman webapp

Posted by: admin November 30, 2017 Leave a comment

Questions:

I’m trying to build my webapp using generator-webapp(sass w/compass + boostrap-sass). However, I don’t want it to minify any of the files. (At least just the css, but ideally nothing will be minified). At my job I’ll be doing a bit of backend that is done in .NET/C# as well as but mostly front end, hence why I need the HTML to not be minified so I can import the front end into Visual Studio and be able to manipulate it.

Currently, I’m trying to configure my gruntfile to stop the minification but I’m having a difficult time finding a solution.

Here is my gruntfile (it’s just the default one that is generated)

Thanks for any help!

Answers:

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:

To this:

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 :)):

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

I hope that might be helpful to someone else.

Questions:
Answers:

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.

Questions:
Answers:

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

To