【问题标题】:Grunt Copy Flatten not working as expectedGrunt Copy Flatten 未按预期工作
【发布时间】:2013-12-24 07:28:14
【问题描述】:

我的目录结构如下:

source/
    libraries/
        d3.js
        lodash.js
        //etc

我的 grunt-copy 设置如下:

copy: {
  main: {
    files: [
      {
        src: ["source/libraries/*.js"], 
        dest: "build/", 
        flatten: true
      }

我希望它将输出扁平化为构建,这样我就有了

build/
    d3.js
    //etc

相反,我在 build 中获得了原始目录结构的复制:

build/
    source/
        libraries/
            d3.js
            //etc

什么给了?我没有正确使用 flatten 吗?

【问题讨论】:

    标签: gruntjs grunt-contrib-copy


    【解决方案1】:

    好吧,如果您只使用flatten 是因为您希望source/libraries 中的所有内容都进入build,那么我建议您实际上使用cwd(当前工作目录)选项。另一方面,如果您实际上在source/libraries 中有子文件夹,那么您可能希望src 行是source/libraries/**/*.js

    无论如何,如果您可以改用cwd,它会是这样的:

    copy: {
      main: {
        files: [
          {
            src: ["*.js"],
            dest: "build/",
            cwd: "source/libraries/"
          }
        ]
      }
    

    对于另一种情况,也许是这个? (注意expand 选项设置为true

    copy: {
      main: {
        files: [
          {
            src: ["source/libraries/**/*.js"],
            dest: "build/",
            flatten: true,
            expand: true
          }
        ]
      }
    }
    

    【讨论】:

    • 使用 cwd 确实解决了我的问题。但是,根据 grunt 文档,看起来 flatten 应该也可以工作:"flatten Remove all path parts from generated dest paths."你知道为什么它不起作用吗?
    • 您是否也尝试添加expand 选项?每次我看到flatten 时,我都会看到expand
    • 嘿...刚刚阅读文档...在您提到的那一行上方是这样的:“expand 设置为true 以启用以下选项:”(flatten是“以下选项”之一)。 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 2022-01-24
    • 2015-05-11
    • 2020-05-15
    • 2014-10-31
    • 2018-02-12
    相关资源
    最近更新 更多