Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt Copy Flatten not working as expected

I have a directory structure as follows:

source/
    libraries/
        d3.js
        lodash.js
        //etc

I have grunt-copy setup as follows:

copy: {
  main: {
    files: [
      {
        src: ["source/libraries/*.js"], 
        dest: "build/", 
        flatten: true
      }

I expect it to flatten the output into build, so that I will have

build/
    d3.js
    //etc

Instead, I get a reproduction of the original directory structure in build:

build/
    source/
        libraries/
            d3.js
            //etc

What gives? Am I not using flatten properly?

like image 577
dandelion Avatar asked Dec 23 '13 23:12

dandelion


1 Answers

Well, if you're only using flatten because you want everything in source/libraries to go into build, I would suggest actually using the cwd (current working directory) option instead. If, on the other hand, you actually have subfolders in source/libraries then you probably want that src line to be source/libraries/**/*.js.

In any case, if you can use cwd instead it would look like this:

copy: {
  main: {
    files: [
      {
        src: ["*.js"],
        dest: "build/",
        cwd: "source/libraries/"
      }
    ]
  }

For the other case, maybe this? (Notice the expand option set to true)

copy: {
  main: {
    files: [
      {
        src: ["source/libraries/**/*.js"],
        dest: "build/",
        flatten: true,
        expand: true
      }
    ]
  }
}
like image 191
Jordan Kasper Avatar answered Sep 20 '22 13:09

Jordan Kasper