使用grunt js来缩小和连接没有* .con.js文件

时间:2013-01-22 19:10:00

标签: javascript concatenation minify gruntjs

我一直在使用grunt.js来连接然后缩小javascript文件。我完成这项任务的方式给我留下了一个额外的script.con.js文件(连接文件)。除了暂存一个连接文件以进行缩小之外,我发现它没有必要。我在下面的例子中缺少什么?

module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
        concat: {
            'app/webroot/js/script.con.js': [
                'app/webroot/js/plugins/plugins.js',
                'app/webroot/js/main.js'
            ]
        },
        min: {
            'app/webroot/js/script.min.js': 'app/webroot/js/script.con.js'
        },
        watch: {
            files: ['app/webroot/js/main.js'],
            tasks: 'concat min'
        }
    });

    // Default task.
    grunt.registerTask('default', 'concat min');

};

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

如果存在minify任务,首先是concat,然后是minifys,你可以使用该任务(我认为到目前为止还没有这样的任务)。

您可以使用一些干净的任务删除con.js文件:https://github.com/reputation/grunt-clean

答案 1 :(得分:2)

连接和缩小对我来说是这样的:

grunt.initConfig({
    min: {
        dist: {
            src: ['lib/js/file1.js', 'lib/js/file2.js'],
            dest: 'lib/js/result.min.js'
        }
    }
});