这是我的卷宗
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');
});我需要复制client文件夹中的所有js文件并复制到公用文件夹。但是这个带有文件夹的代码副本和我的公用文件夹看起来像
公共->客户端库->myjsfiles
但我需要
公共->myjsfiles
发布于 2017-11-14 12:13:20
--你不需要为此使用任何NPM,
remove `const gulpCopy = require('gulp-copy');` ,并将此命令从gulpCopy任务中提取。
然后简单的尝试
gulp.task('move-file',function(){
gulp .src('client-lib/*.js') .pipe(rename({dirname: ''}))
.pipe(gulp.dest('./public'))
});发布于 2017-11-14 12:19:43
您可以使用一个名为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'));
});更多答案:
Can you remove a folder structure when copying files in gulp?
发布于 2019-05-23 10:54:05
gulp.task('move-file',function(){
console.log("Move-files");
return gulp
.src(['./client-lib/*.js'])
.pipe(gulpCopy('./public', { prefix: 1 }))
})以下是解释:https://www.npmjs.com/package/gulp-copy#options
gulp-copy有一个options对象,您可以在其中使用prefix值。如果将其设置为1,它将删除由路径的"/“分隔的1部分。在你的例子中,1就足够了。如果要删除所有目录,请使用99。
https://stackoverflow.com/questions/47284460
复制相似问题