Grunt任务-移动文件从一个文件夹到另一个



我在编写本地函数时会遇到问题,该函数会将我的文件从一个目录复制到另一个目录,并排除正在处理的一些文件和目录。

module.exports = function(grunt) {
   grunt.initConfig({
        //....
        copy: {
            prod: {
                src: ["./src/*"],
                dest: ["build/"]
            }
        }   
    }
}

这是我的自定义任务负载:

    grunt.loadNpmTasks('copy', function(){
        var src = grunt.config.get('copy.src'),
            dest = grunt.config.get('copy.dest'),
            grunt.file.copy(src, dest);
    });

我在控制台得到这个错误:

警告:任务"copy"未找到。

我认为这是原生的grunt功能:http://gruntjs.com/api/grunt.file

然后我的prod看起来像这样:

    grunt.registerTask("prod", ["concat", "uglify", "htmlmin", "imagemin", "copy"]);

我猜这毕竟不是一个原生的grunt函数。您可以安装"copy",而无需编写自定义的Task Load函数。

Install copy from:

npm install grunt-contrib-copy --save-dev

关于插件的更多信息:https://github.com/gruntjs/grunt-contrib-copy

我在init中重新配置了我的Copy Task:

        copy: {
            prod: {
                files: [
                    {expand: true, src: ['./src/**'], dest: 'build/'}
                ]
            }
        }   

包含

grunt.loadNpmTasks('grunt-contrib-copy');

。现在起作用了。

最新更新