2

我有一个很大的目录结构,这是大多数应用程序的典型结构。

例如,像这样:

theprojectroot
|- src
|     |- app
|     |     |- index.html
|     |     |- index.js
|     |     |- userhome
|     |     |     |- userhome.html
|     |     |     |- userhome.js
|     |     |- management
|     |     |     |- management.html
|     |     |     |- management.js
|     |     |- social
|     |     |     |- social.html
|     |     |     |- social.js
|     |- assets
|- vendor
|- package.json

我想将所有目录中的所有HTML文件(HTML 文件)复制到另一个文件夹中。

我目前正在使用 Gruntcopy复制所有文件,但现在我只想为 HTML 这样做。在 docs中,似乎没有任何选择文件类型的选项。

有没有人可以建议这样做的黑客?

4

2 回答 2

9

以下代码将起作用

copy: {
    files: {
        cwd: 'path/to/files',  // set working folder / root to copy
        src: '**/*.html',      // copy all files and subfolders **with ending .html**
        dest: 'dist/files',    // destination folder
        expand: true           // required when using cwd
      }
    }
于 2015-07-31T05:24:35.803 回答
0

这个答案中的 flatten: true 选项可能适用于某些情况,但在我看来,更常见的要求(如我的情况)是将文件夹及其子文件夹结构按原样复制到 dest。似乎在大多数情况下,如果您有子文件夹,它们可能会在代码中以这种方式被引用。这样做的关键是 cwd 选项,它将保留相对于指定工作目录的文件夹结构:

copy: {
  files: {
    cwd: 'path/to/files',  // set working folder / root to copy
    src: '**/*.html',      // copy only html files
    dest: 'dist/files',    // destination folder
    expand: true           // required when using cwd
  }
}
于 2015-01-26T09:31:13.240 回答