【问题标题】:Copy folder structure from src/ to dist/ using grunt-contrib-copy使用 grunt-contrib-copy 将文件夹结构从 src/ 复制到 dist/
【发布时间】:2015-05-06 17:49:47
【问题描述】:

我有一个看起来像这样的文件夹结构

我想将文件夹 img/ 从 src/ 复制到 dist/ 文件夹。

我使用下面的 grunt 命令,使用grunt-contrib-copy:

copy:{
       main : {
                files : [
                    {
                        flatten : true,
                        expand: true,
                        src: ['src/img/*'],
                        dest: 'dist/img'
                    }
                ]
            }
        }

但我的文件夹结构最终是这样的。缺少图标文件夹中的图像:

基本上,我想做 linux 命令(当我位于项目的根目录时):

cp -r src/img dist/img

我该怎么做?

【问题讨论】:

  • grunt-cp 具有 dir 的递归副本。可以试试吗?

标签: node.js gruntjs grunt-contrib-copy


【解决方案1】:

将 flatten 设置为 false flatten : false 并将 src 更改为 ['src/img/**'] 以包含子目录(来源:https://github.com/gruntjs/grunt-contrib-copy)

copy:{
   main : {
            files : [
                {
                    flatten : false,
                    expand: true,
                    src: ['src/img/**'],
                    dest: 'dist/img'
                }
            ]
        }
    }

【讨论】:

    【解决方案2】:

    通过以下方式解决:

    copy:{
    
        main : {
            files : [
                {
                    cwd: 'src/',
                    expand: true,
                    src: ['img/**'],
                    dest: 'dist/'
                }
    
    
            ]
        }
    }
    

    显然需要设置 cwd 才能使其正常工作。

    【讨论】:

      猜你喜欢
      • 2017-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 2013-08-17
      • 1970-01-01
      • 2019-02-06
      相关资源
      最近更新 更多