[英]Gulp copy all files inside a directory , without directory
This is my gulpfile 这是我的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 . 我需要将所有js文件复制到client-lib文件夹中,然后复制到public文件夹中。 But this code copy with folder and my public folders look like
但是此代码副本与文件夹和我的公用文件夹看起来像
public->client-lib->myjsfiles
公共->客户端库-> myjsfiles
But I need 但是我需要
public->myjsfiles
public-> myjsfiles
You dont need to use any NPM for this , 您不需要为此使用任何NPM,
remove `const gulpCopy = require('gulp-copy');` ,
and gulpCopy this command from task as well . 和gulp也从task复制这个命令。
and simply try 并尝试
gulp.task('move-file',function(){
gulp .src('client-lib/*.js') .pipe(rename({dirname: ''}))
.pipe(gulp.dest('./public'))
});
You can use a library called gulp-rename
and here's simple example: 您可以使用一个名为
gulp-rename
的库,下面是一个简单的示例:
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? 在gulp中复制文件时可以删除文件夹结构吗?
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 解释如下: https : //www.npmjs.com/package/gulp-copy#options
gulp-copy
has an options
object, where you could use prefix
value. gulp-copy
有一个options
对象,您可以在其中使用prefix
值。 If you set it to 1, it would remove 1 part separated by "/" of your path. 如果将其设置为1,它将删除路径的“ /”分隔的1部分。 In your case 1 is enough.
在您的情况下1就足够了。 If you want to remove all directories, then use 99.
如果要删除所有目录,请使用99。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.