Gruntjs 如何使grunt contrib复制而不是复制更少的文件?

Gruntjs 如何使grunt contrib复制而不是复制更少的文件?,gruntjs,Gruntjs,我有以下文件: module.exports = function(grunt) { //Project configuration. grunt.initConfig({ copy: { main: { files: [ { expand: true, cwd:

我有以下文件:

module.exports = function(grunt) {
    //Project configuration.
    grunt.initConfig({      
        copy: {
            main: {
                files: [
                    {
                        expand: true,
                        cwd: "source/",
                        src: ["!**/*.less", "**"],
                        dest: "compiled/"
                    },
                ],
            },
        },
    });

    grunt.loadNpmTasks("grunt-contrib-copy");
    grunt.registerTask("default", ["copy"]);
};
我的目标是让它将
source
文件夹中的所有内容复制到
compiled
文件夹中。例如,如果这是我在运行Grunt之前的文件结构

[root]
 - Gruntfile.js
 - source
    \- test.txt
    \- sample.html
    \- file.less
 - compiled
…我希望得到

[root]
 - Gruntfile.js
 - source
    \- test.txt
    \- sample.html
    \- file.less
 - compiled
    \- test.txt
    \- sample.html
…但我得到的是:

[root]
 - Gruntfile.js
 - source
    \- test.txt
    \- sample.html
    \- file.less
 - compiled
    \- test.txt
    \- sample.html
    \- file.less

我认为将源代码设置为
[“!***/*.less”、“***”]
可以解决这个问题,但事实并非如此。为什么这不起作用(它的实际目标是什么)以及我如何解决这个问题?

否定模式应该放在匹配模式之后,因为它们否定了之前的匹配:

copy: {
  main: {
    files: [
      {
        expand: true,
        cwd: "source/",
        src: ["**", "!**/*.less"],
        dest: "compiled/"
      },
    ],
  },
}
有关示例,请参见:

// All files in alpha order, but with bar.js at the end.
{src: ['foo/*.js', '!foo/bar.js', 'foo/bar.js'], dest: ...}

通过将
“**”
置于否定模式之后,您正在覆盖它。

否定先前的模式,所以将其放在匹配模式之后。@steveax如下所示:
src:[“***.less!”,“***”]
或者您的意思是这样的:
src:[“***”,“!***.less”]