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

时间:2021-10-17 07:53:02

I've been using grunt.js to concatenate and then minify javascript files. The way I've been accomplishing this task leaves me with an extra script.con.js file (the concatenated file). I don't find it really necessary other than staging a concatenated file to minify. What am I missing in my example below?

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

};

Thank you in advance for your help.

预先感谢您的帮助。

2 个解决方案

#1


2  

if a minify task exists which first concats and then minifys, you could use that task (i dont think there is such a task until now).

如果存在一个minify任务,第一个concats然后minifys,你可以使用该任务(我认为直到现在才有这样的任务)。

you can delete the con.js file with some clean task: https://github.com/reputation/grunt-clean

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

#2


2  

Concatenation and minification works for me like this:

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

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

#1


2  

if a minify task exists which first concats and then minifys, you could use that task (i dont think there is such a task until now).

如果存在一个minify任务,第一个concats然后minifys,你可以使用该任务(我认为直到现在才有这样的任务)。

you can delete the con.js file with some clean task: https://github.com/reputation/grunt-clean

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

#2


2  

Concatenation and minification works for me like this:

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

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