How to stop minification of js files in grunt?
Asked Answered
G

2

8

I am new to grunt. I have nearly 20-30 js files in my project. I came to know that We are already using grunt to minify and concatenate them. For debug purpose I need to stop minification but retain them in concatenated form. Could any one suggest how to proceed. Any site which has the related tutorials would be helpful.Thanks in advance.

module.exports = function(grunt) {
 var readJSFile = function(data, path){
    var finalArray = [];
    if(path == 'assets/js/'){
        finalArray.push('<%= copy.options.buildFolder %>/JSON-words.js');
    }
    for(var item in data.main){
        finalArray.push('<%= copy.options.buildFolder %>/'+path+data.main[item].file);
    }
    return finalArray;
}
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    exec: {
        update: {
            command: 'TortoiseProc.exe /command:update /path:"./**" /closeonend:3'
        }
    },
    copy: {
        options : {
            buildFolder : '../../deliverables/<%= pkg.folder %>/<%= grunt.template.today("yyyymmdd") %>-htdocs'
        },
        main: {
            files: [
                {expand: true, src: ['./**'], dest: '<%= copy.options.buildFolder %>'}
            ]
        }
    }, 
    'useminPrepare': {
        html: ['<%= copy.options.buildFolder %>/inc/general/head.html', '<%= copy.options.buildFolder %>/inc/general/foot.html', '<%= copy.options.buildFolder %>/inc/module/print.html']
    },
    usemin: {
      html: ['<%= copy.options.buildFolder %>/inc/general/head.html', '<%= copy.options.buildFolder %>/inc/general/foot.html', '<%= copy.options.buildFolder %>/inc/module/print.html']
    },
    concat: {
        options: {
            separator: ''
        },

        // JS build starts here
        mainJS: {
            src : readJSFile(grunt.file.readJSON('buildFiles/mainjs.json'), 'assets/js/'),
            dest: '<%= copy.options.buildFolder %>/assets/js/<%= pkg.name %>.min.js'
        },
        libheaderJS: {
            src: readJSFile(grunt.file.readJSON('buildFiles/headerjs.json'), 'assets/js/libs/headerJS/'),
            dest: '<%= copy.options.buildFolder %>/assets/js/libs/headerJS/ladbrokes.lib.top.js'
        },
        libbetdaqJS: {
            src: readJSFile(grunt.file.readJSON('buildFiles/betdaqjs.json'), 'assets/js/libs/betdaqJS/'),
            dest: '<%= copy.options.buildFolder %>/assets/js/libs/betdaqJS/ladbrokes.betdaq.js'
        },
        commonJS: {
            src: readJSFile(grunt.file.readJSON('buildFiles/common.json'), 'assets/js/'),
            dest: '<%= copy.options.buildFolder %>/assets/js/common.min.js'
        },
        racingJS: {
            src: readJSFile(grunt.file.readJSON('buildFiles/racing.json'), 'assets/js/'),
            dest: '<%= copy.options.buildFolder %>/assets/js/racing.min.js'
        },
        landingJS: {
            src: readJSFile(grunt.file.readJSON('buildFiles/landing.json'), 'assets/js/'),
            dest: '<%= copy.options.buildFolder %>/assets/js/landing.min.js'
        },
        // ladbrokes.min.css starts here
        mainCSS: {
            src: readJSFile(grunt.file.readJSON('buildFiles/maincss.json'), 'assets/css/'),
            dest : '<%= copy.options.buildFolder %>/assets/css/ladbrokes.min.css'
        },
        globalCSS: {
            src: readJSFile(grunt.file.readJSON('buildFiles/globalcss.json'), 'assets/css/'),
            dest : '<%= copy.options.buildFolder %>/assets/css/global.min.css'
        },
        responsiveCSS: {
            src: readJSFile(grunt.file.readJSON('buildFiles/responsivecss.json'), 'assets/css/'),
            dest : '<%= copy.options.buildFolder %>/assets/css/ladbrokes.responsive.css'
        }
    },
    uglify: {
        options: {
           // dont make comma separted all the statements so that it can be debug on live env.
            compress :{
                sequences : false
            },
            banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> <%= grunt.template.today("HH-MM-ss") %> */\n'
        },
        mainJS: {
            files: {
              '<%= copy.options.buildFolder %>/assets/js/<%= pkg.name %>.min.js': ['<%= concat.mainJS.dest %>']
            }
        },
        libheaderJS: {
            files: {
              '<%= copy.options.buildFolder %>/assets/js/libs/headerJS/ladbrokes.lib.top.js': ['<%= concat.libheaderJS.dest %>']
            }
        },
        libbetdaqJS: {
            files: {
                '<%= copy.options.buildFolder %>/assets/js/libs/betdaqJS/ladbrokes.betdaq.js': ['<%= concat.libbetdaqJS.dest %>']
            }
        },
        commonJS: {
            files: {
                '<%= copy.options.buildFolder %>/assets/js/common.min.js': ['<%= concat.commonJS.dest %>']
            }
        },
        racingJS: {
             files: {
                '<%= copy.options.buildFolder %>/assets/js/racing.min.js': ['<%= concat.racingJS.dest %>']
            }
        },
        landingJS: {
            files: {
                '<%= copy.options.buildFolder %>/assets/js/landing.min.js': ['<%= concat.landingJS.dest %>']
            }
        },
        configJS: {
            files: {
              '<%= copy.options.buildFolder %>/assets/js/ladbrokes.config.prod.min.js': ['<%= copy.options.buildFolder %>/assets/js/ladbrokes.config.prod.js']
            }
        }
    },
     // CSS build starts here
    cssmin: {
        my_target: {
           src: '<%= copy.options.buildFolder %>/assets/css/ladbrokes.min.css',
           dest : '<%= copy.options.buildFolder %>/assets/css/ladbrokes.min.css'
        },
        globalCSS: {
          src : '<%= copy.options.buildFolder %>/assets/css/global.min.css',
          dest : '<%= copy.options.buildFolder %>/assets/css/global.min.css'
        },
        printCSS: {
          src: '<%= copy.options.buildFolder %>/assets/css/print.css',
          dest: '<%= copy.options.buildFolder %>/assets/css/print.min.css'
        },
        racingCSS: {
          src: '<%= copy.options.buildFolder %>/assets/css/racing.css',
          dest: '<%= copy.options.buildFolder %>/assets/css/racing.min.css'
        },
        landingCSS: {
          src: '<%= copy.options.buildFolder %>/assets/css/landing.css',
          dest: '<%= copy.options.buildFolder %>/assets/css/landing.min.css'
        },
        responsiveCSS:{
          src: '<%= copy.options.buildFolder %>/assets/css/ladbrokes.responsive.css',
          dest: '<%= copy.options.buildFolder %>/assets/css/ladbrokes.responsive.min.css'  
        }

    },

    clean: {
        options: {
            force: true
        },
        src0: '<%= concat.mainJS.src %>',
        src1: '<%= concat.libheaderJS.src %>',
        src3: '<%= concat.mainCSS.src %>',
        src4: '<%= concat.globalCSS.src %>',
        src5: [
            '<%= copy.options.buildFolder %>/script',
            '<%= copy.options.buildFolder %>/buildFiles',
            '<%= copy.options.buildFolder %>/node_modules',
            '<%= copy.options.buildFolder %>/Gruntfile.js',
            '<%= copy.options.buildFolder %>/package.json',
            '<%= copy.options.buildFolder %>/assets/js/libs/headerJS/jquery.min.js',
            '<%= copy.options.buildFolder %>/assets/js/ladbrokes.config.dev.js',
            '<%= copy.options.buildFolder %>/assets/js/libs/footerJS/mtagconfig.js', 
            '<%= copy.options.buildFolder %>/assets/js/libs/footerJS/plugins.js',
            '<%= copy.options.buildFolder %>/assets/js/ladbrokes.beta.js', 
            '<%= copy.options.buildFolder %>/assets/js/ladbrokes.config.prod.js',
            '<%= copy.options.buildFolder %>/assets/js/respond.js',
            '<%= copy.options.buildFolder %>/assets/css/global.css', 
            '<%= copy.options.buildFolder %>/assets/css/print.css', 
            '<%= copy.options.buildFolder %>/assets/css/beta-site.css', 
            '<%= copy.options.buildFolder %>/assets/css/betslip.css', 
            '<%= copy.options.buildFolder %>/assets/css/mediaelementplayer.min.css',
            '<%= copy.options.buildFolder %>/assets/css/landing.css',
            '<%= copy.options.buildFolder %>/assets/css/minigames.css',
            '<%= copy.options.buildFolder %>/assets/css/nownextpool.css',
            '<%= copy.options.buildFolder %>/assets/css/racing.css',
            '<%= copy.options.buildFolder %>/assets/css/toteslip.css',
            '<%= copy.options.buildFolder %>/assets/css/*.scss',
            '<%= copy.options.buildFolder %>/assets/css/ladbrokes.responsive.css',
            '<%= copy.options.buildFolder %>/assets/css/generic-responsive.css',
            '<%= copy.options.buildFolder %>/assets/css/higher-resolution.css',
            '<%= copy.options.buildFolder %>/assets/css/ladbrokes-maxw-1200.css',
            '<%= copy.options.buildFolder %>/JSON-words.js'
        ],
        src6: readJSFile(grunt.file.readJSON('buildFiles/jsIgnore.json'), 'assets/js/'),
        src7: '<%= concat.libbetdaqJS.src %>',
    },


    shell: {
        add: {
           command: 'TortoiseProc.exe /command:commit /path:"<%= copy.options.buildFolder %>/"/logmsg:"Please verify this build before commit !" /closeonend:0'
        }
    },

    smushit: {
        path:{
            src:'<%= copy.options.buildFolder %>/assets/images'
        }
    }


});

grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-css');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-rename');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-smushit');

grunt.registerTask('default', [
    'exec', 
    'copy', 
    'concat', 
    'uglify', 
    'cssmin', 
    'useminPrepare', 
    'usemin', 
    'clean'/*, 'smushit'*/, 
    'shell'
    ]
);

};

Gherlein answered 7/11, 2013 at 12:33 Comment(0)
B
4

Look in the Gruntfile. There is probably a reference to a task named "min". Try to remove that reference and run grunt again.

For a more detailed answer you need to add the Gruntfile to the question.

Edit: It could also be called uglify. Look for a line like this at the end:

grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']);

and remove the last option. You might also have to change some file paths.

Beauvoir answered 7/11, 2013 at 12:36 Comment(2)
thanks a lot for the quick reply. I will try the above solution.@Eivind Eidheim ElsethGherlein
If I remove the reference to min wouldn't the minimization of other css also get removed?I want everything except js files to be minified.I have edited the question and added Grunt file code.Please share your thoughts. @Eivind Eidheim ElsethGherlein
B
0

Just need to set all minimize options to false in Gruntfile.js.

optimization: {
    minimize: false
}
Bisitun answered 17/2, 2019 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.