4

This is my gulpfile

const gulp = require('gulp');
const runSequence = require('run-sequence');
const gulpCopy = require('gulp-copy');

//move client side library from client-lib to public folder
gulp.task('move-file',function(){
    console.log("Move-files");
    return gulp
        .src(['./client-lib/*.js'])        
        .pipe(gulpCopy('./public'))        

});

gulp.task('default',function(){   
    runSequence('move-file');
});

I need to copy all js files inside client-lib folder and copy to public folder . But this code copy with folder and my public folders look like

public->client-lib->myjsfiles

But I need

public->myjsfiles

Ashutosh Jha
  • 15,451
  • 11
  • 52
  • 85
  • You can find good solutions here: https://stackoverflow.com/questions/24658011/can-you-remove-a-folder-structure-when-copying-files-in-gulp – Dabbas Nov 14 '17 at 11:22
  • 1
    You can use the [`prefix`](https://www.npmjs.com/package/gulp-copy#options) option. Give it a value, such as 99, to remove all the paths. – 31piy Nov 14 '17 at 11:22
  • Possible duplicate of [Can you remove a folder structure when copying files in gulp?](https://stackoverflow.com/questions/24658011/can-you-remove-a-folder-structure-when-copying-files-in-gulp) – Jorge Fuentes González Nov 14 '17 at 11:23
  • I tried accepted answer but wont work in my case @Dabbas – Ashutosh Jha Nov 14 '17 at 11:25

3 Answers3

1

You dont need to use any NPM for this ,

remove `const gulpCopy = require('gulp-copy');` ,

and gulpCopy this command from task as well .

and simply try

gulp.task('move-file',function(){ 
gulp .src('client-lib/*.js') .pipe(rename({dirname: ''})) 
.pipe(gulp.dest('./public')) 
});
Ashutosh Jha
  • 15,451
  • 11
  • 52
  • 85
GsMalhotra
  • 1,837
  • 3
  • 14
  • 22
  • What if i need to just copy my packages with 1-3 MiB of code? Gulp reads it and it slows down the task for a long. – RamoFX May 11 '20 at 20:16
0

You can use a library called gulp-rename and here's simple example:

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

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

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

Dabbas
  • 3,112
  • 7
  • 42
  • 75
0
gulp.task('move-file',function(){
    console.log("Move-files");
    return gulp
        .src(['./client-lib/*.js'])        
        .pipe(gulpCopy('./public', { prefix: 1 }))        

})

Here's explanation: https://www.npmjs.com/package/gulp-copy#options

gulp-copy has an options object, where you could use prefix value. If you set it to 1, it would remove 1 part separated by "/" of your path. In your case 1 is enough. If you want to remove all directories, then use 99.

Alexander Kim
  • 17,304
  • 23
  • 100
  • 157