Yeoman Grunt HTMLMin copy all files in subdirectories to same folder structure in dist

516 Views Asked by At

Looking for the right regular expression(s) to mirror the folder structure from "app" to the "dist" folder.

E.g. app/components/search/a.html app/components/search/b.html etc.

To: dist/components/search/a.html dist/components/search/b.html etc.

My current grunt htmlmin entry:

htmlmin: {
            dist: {
                options: {
                    collapseWhitespace: true,
                    collapseBooleanAttributes: true,
                    removeCommentsFromCDATA: true,
                    removeOptionalTags: true
                },
                files: {
                    '<%= yeoman.dist %>/components/search' : '<%= yeoman.app %>/components/search/**/*.html'
                }
            }
        },

Have tried several other combinations unsuccessfully.

1

There are 1 best solutions below

0
binarygiant On

Turns out there is a pretty decent template for doing this in the Grunt file that Yeoman generate for Angular.

The yeoman generator directory style isn't quite what I wanted, so the default doesn't work. I've amended it to fit my needs.

My solution:

htmlmin: {
            dist: {
                options: {
                    collapseWhitespace: true,
                    collapseBooleanAttributes: true,
                    removeCommentsFromCDATA: true,
                    removeOptionalTags: true
                },
                files: [
                    {
                        expand: true,
                        cwd: '<%= yeoman.app %>/components',
                        src: '{,*/}*.html',
                        dest: '<%= yeoman.dist %>/components'
                    }
                ]
            }
        }