---
title: "grunt配置-copy任务"
author: "小丑鱼0703"
date: "2015-04-27T20:51:33Z"
tags: []
categories: ["Web前端"]
slug: "grunt-copy"
draft: false
lastmod: "2015-04-27T20:57:52Z"
id: 2206565
url: "https://wangjingyi.iteye.com/blog/2206565"
---

copy任务配置项使用示例：

```java
copy: {
  main: {
    files: [
      // includes files within path 
      {expand: true, src: ['path/*'], dest: 'dest/', filter: 'isFile'},
 
      // includes files within path and its sub-directories 
      {expand: true, src: ['path/**'], dest: 'dest/'},
 
      // makes all src relative to cwd 
      {expand: true, cwd: 'path/', src: ['**'], dest: 'dest/'},
 
      // flattens results to a single level 
      {expand: true, flatten: true, src: ['path/**'], dest: 'dest/', filter: 'isFile'},
    ],
  },
},
```

flatten:设置（true、false）用来指定是否保持文件目录结构

那么配置为如下任务

```java
copy: {
    dev : {
                files : [{
                    expand : true,
                    cwd : 'app',//根目录
                    dest : 'test123',
                    src : '*.html'//基于cwd的子目录
                }]
            }
}
```

执行 grunt copy:dev就将app目录下所有的html文件都复制到app/test123目录下

<https://github.com/gruntjs/grunt-contrib-copy>
<http://blog.sina.com.cn/s/blog_79c02b6b0102v03e.html>