Can you remove a folder structure when copying files in gulp?

Gulp

Gulp Problem Overview


If I use :

 gulp.src(['app/client/**/*.html'])
  .pipe(gulp.dest('dist'));

The folder structure in which my .html files were in, is maintained in the dist folder, but I would like to remove the folder structure completely and just a flat hierarchy in my dist folder.

Gulp Solutions


Solution 1 - Gulp

You could use gulp-rename to accomplish this:

var rename = require('gulp-rename');

gulp.src('app/client/**/*.html')
  .pipe(rename({dirname: ''}))
  .pipe(gulp.dest('dist'));

Solution 2 - Gulp

You can use gulp-flatten https://www.npmjs.com/package/gulp-flatten

app
├── logo
│   └── logo.styl
└── sidebar
└── sidebar.styl
var flatten = require('gulp-flatten');
gulp.src('app/**/*.styl')
.pipe(flatten())
.pipe(gulp.dest('dist/'));
dist
├── logo.styl
└── sidebar.styl

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioni_am_elliotView Question on Stackoverflow
Solution 1 - GulpBenView Answer on Stackoverflow
Solution 2 - Gulpc01nd01rView Answer on Stackoverflow