使用grunt js来缩小和连接,而不需要*.con.js文件

Using grunt js to both minify and concatenate without a *.con.js file

本文关键字:js 不需要 con 文件 连接 grunt 缩小 使用      更新时间:2023-09-26

我一直在使用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');
};

提前感谢您的帮助

如果存在先concats然后minifys的minify任务,您可以使用该任务(我认为直到现在还没有这样的任务)。

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

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

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