javascriptgruntjsgrunt-usemin

Conditional js minification with Grunt


I have single page angular app which codes are minified and concated before build. It works fine with grunt use-min task and build blocks in index.html

<!-- build:js js/components.min.js -->
<script src="components/jquery/dist/jquery.js"></script>
<!-- other bower components -->
<!-- endbuild -->

<!-- build:js js/app.min.js -->
<script src="js/app.js"></script>
<!-- other application specific js files -->
<!-- endbuild -->

It at the end creates two files: app.min.js and components.min.js.

But now I need to parametrize grunt task to generate app.min.js based on parameter. (I need one build where everything will be minified for production and other one - without minified application code - for "business" purpose).

How to configure useminPrepare to sometimes take all the blocks and sometimes no?


Solution

  • As I didn't get any valid answer here is my work-around:

    1. create separate grunt task for 'business' build
    2. regex-replace all usemin build comments that are not wanted before processing index.hmtl with useminPrepare
    3. make all processing
    4. restore index.html from backup