如何在grunt中停止缩小js文件?

时间:2013-11-07 12:33:32

标签: gruntjs grunt-usemin

我是新来的咕噜声。我的项目中有近20-30个js文件。我开始知道我们已经在使用grunt来缩小和连接它们。出于调试目的,我需要停止缩小,但要以连续的形式保留它们。任何人都可以建议如何继续。任何有相关教程的网站都会有所帮助。谢谢。

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'
    ]
);

};

2 个答案:

答案 0 :(得分:4)

查看Gruntfile。可能存在对名为“min”的任务的引用。尝试删除该引用并再次运行grunt。

要获得更详细的答案,您需要将Grunt文件添加到问题中。

编辑:它也可以被称为uglify。在最后寻找这样的一行:

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

并删除最后一个选项。您可能还需要更改一些文件路径。

答案 1 :(得分:0)

只需在Gruntfile.js中将所有最小化选项设置为false。

optimization: {
    minimize: false
}