当任务运行时,我使用gulp-notify在终端中显示额外的信息。目前我只能在我的硬盘上获得完整的路径和文件名。我更喜欢只显示项目文件夹,因为它更干净。
function copyVideo (done) {
// Locate files
return gulp.src('./src/assets/video/*')
// Copy the files to the dist folder
.pipe(gulp.dest('./dist/assets/video'))
// Notify the files copied in the terminal
.pipe(notify('Copied <%= file.relative %> to <%= file.path %>')),
done();
}终端视图

我希望终端简单地说*将快速范围-for-6.mp4复制到\dist\assets\video*
我已经尝试过<%= folder.path %>和<%= directory.path %>
发布于 2020-07-13 17:34:08
通过notify(Function) (文档中的here)的形式,您可以使用内置的path.relative方法来获取相对于项目文件夹的目标路径。
var path = require('path');
// ...
function copyVideo (done) {
// Locate files
return gulp.src('./src/assets/video/*')
// Copy the files to the dist folder
.pipe(gulp.dest('./dist/assets/video'))
// Notify the files copied in the terminal
.pipe(notify(file => {
var destFolder = path.dirname(file.path);
var projectFolder = path.dirname(module.id); // Also available as `module.path`
return `Copied ${file.relative} to ${path.relative(projectFolder, destFolder)}`;
})),
done();
}https://stackoverflow.com/questions/62742789
复制相似问题