简体   繁体   English

如何在Grunt Build中使用多个复制命令?

[英]How do I use multiple copy commands in Grunt Build?

I would like to copy some files, run other tasks, and then again copy some files: 我想复制一些文件,运行其他任务,然后再复制一些文件:

copy:{....},
concat:{...},
copy:{...}

However, I get the following error when I run my grunt build: 但是,当我运行我的grunt构建时,我收到以下错误:

SyntaxError: Duplicate data property in object literal not allowed in strict mode

Of course I understand, that I cannot use the same property (ie "copy") multiple times in the grunt json. 当然我明白,我不能在grunt json中多次使用相同的属性(即“copy”)。 But what is the solution to my problem? 但是我的问题的解决方案是什么? How can I copy at different positions of the gruntfile.js? 如何在gruntfile.js的不同位置复制?

Many thanks! 非常感谢!

Just split your copy comment in the desired subtasks: 只需将您的copy注释拆分为所需的子任务:

copy: {
    task1: {
        files: [...]
    }
    task2: {
        files: [...]
    },
    task3: {
        files: [...]
    }
}

And then run Grunt like that: 然后像这样运行Grunt:

grunt.registerTask('development', [ 'copy:task1', 'concat', 'copy:task2' ]);

I do the same job like this. 我做同样的工作。 Here is my task, right at the end of the Gruntfile: 这是我的任务,就在Gruntfile的末尾:

grunt.registerTask('client', [
    'concat:app_js',
    'concat:lib_js',
    'uglify:app_lib_js',
    'concat:client_js',
    'concat:client_css',
    'includes',
    'concat:client_html',
    'copy:client_gfx',
    'copy:client_xml'
]);

This is referencing a structure higher up that looks like: 这是引用一个更高的结构,如下所示:

module.exports = function(grunt) {

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    concat: { ... concat jobs here ... },

    // This is how to have multiple copy jobs
    copy: {
        client_gfx: {
            // spec here
        },
        client_xml: {
            // spec here
        }
    }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM