buildgruntjsgrunt-contrib-copy

Using Grunt.js to copy all HTML files from one directory structure to another


I have a large directory structure, typical of most apps.

For example, like this:

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

I would like to copy all the HTML files - and ONLY the HTML files - in all the directories into another folder.

I'm currently using Grunt copy to copy all files, but now I'd like to do so just for the HTML. In the docs, there doesn't seem to be any option to select a file type.

Does anyone have a hack they could suggest to do this?


Solution

  • The following code will work

    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
          }
        }