4

不确定我是否遗漏了什么,但我为 grunt-contrib-copy 任务设置了以下 grunt 设置。

copy: {
  build: {
    files: {
      "server-dist/": "server/**/*.!(coffee)",
      "client-dist/": "client/**/*.!(coffee)"
    }
  }
}

正如我期望的那样,client-dist 复制文件树递归地运行,但 server-dist 所有子文件夹都被展平到基本文件夹。任何想法为什么会发生这种情况?这是输入/输出

server/
  views/
    errors/
      404.jade
    layouts/
      base.jade

变成

server/
  errors/
  layouts/
    base.jade

视图文件夹被完全炸毁。还有一件事……当我删除 !(coffee) 时,它可以工作,但我需要排除咖啡文件,因为我有一个 grunt-coffee watch 任务正在运行。

4

2 回答 2

9

A followup to zacks comment:

copy: {  
    mytask: {  
        files: [  
        {expand:true, cwd:'dev-js/abc/', dest:'js/test/', src:['def.js']}  
        ]  
    }  
}  

This copies the file ./dev-js/abc/def.js to ./js/test/def.js - at least on my 0.4.1 version. Zacks comment and the link included was very helpful, especially the fact, that basePath has been replaced.

于 2013-05-04T08:54:23.963 回答
2

显然,该grunt-contrib-copy任务有一个复杂的逻辑,它试图自动检测复制源文件的基本目录(参见相关问题

解决方案是明确指定basePath选项:

copy: {
  build: {
    files: {
      "server-dist/": "server/**/*!(.coffee)"
    },
    options: {
      basePath: 'server' // base directory in the source path
    }
  }
}

P.S. I'm not sure, however, why removing !(.coffee) changes the behaviour for you. I tried the same on my local machine and get the same results when specifying "server/**/*" instead of "server/**/*.!(coffee)" (i.e. the views folder is skipped)

于 2012-11-16T11:55:30.920 回答