【问题标题】:grunt-contrib-copy copy directory into another without root dirgrunt-contrib-copy 将目录复制到另一个没有根目录的目录
【发布时间】:2015-09-07 15:50:54
【问题描述】:

我正在尝试复制这样的结构:

src
|-a
|-b
|-c
||-ca
||-cb
dest
|-a
|-b
|-c
||-ca
||-cb

但是,如果 src 目录本身没有出现在 dest 目录中,我似乎无法完成此操作。即

src
|-a
|-b
|-c
||-ca
||-cb
dest
|src
||-a
||-b
||-c
|||-ca
|||-cb

我的副本配置是这样设置的:

files: [
    {src: [targetDirectory+"index.html"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"*.png"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+minJSDestination], dest: buildDirectory, expand: true},
    {src: [targetDirectory+minCSSDestination], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"assets/fonts/**.*"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"assets/images/**.*"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"assets/partials/**.*"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"src/*.js"], dest: buildDirectory, expand: true}
]

我尝试了 flatten 选项,该选项从 dest 中删除“src”目录,但它也删除了其他目录并将每个文件放在 dest 的根级别。

我尝试将 'cwd' 设置为目标目录和源目录,但这似乎只是阻止了复制。

我确定必须有一个选项允许这样做,但我还没有找到它。有人有什么想法吗?

【问题讨论】:

标签: javascript gruntjs grunt-contrib-copy


【解决方案1】:

我解决了。我需要从 src 中删除基本目录并添加到 cwd:

即:

{src: ["src/*.js"], dest: buildDirectory, expand: true, cwd: srcDirectory}

而不是

{src: [srcDirectory+"src/*.js"], dest: buildDirectory, expand: true, cwd: srcDirectory}

【讨论】:

  • 同样的问题,同样的解决方案。 cwd 丢失。可惜任务手册中甚至没有提到这个参数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-18
  • 2013-01-11
  • 1970-01-01
  • 2012-09-13
  • 1970-01-01
  • 1970-01-01
  • 2013-10-25
相关资源
最近更新 更多