使用gulp复制文件,同时保留修改时间
情况: 我目前有一个小任务,准备通过FTP部署我的项目文件。这没什么特别的,但是这个简单的项目现在不需要更多 整个部署任务有一个“子任务”,它只需获取路径列表,并将所有文件复制到使用gulp复制文件,同时保留修改时间,gulp,Gulp,情况: 我目前有一个小任务,准备通过FTP部署我的项目文件。这没什么特别的,但是这个简单的项目现在不需要更多 整个部署任务有一个“子任务”,它只需获取路径列表,并将所有文件复制到\u deploy目录: /* Path: Folder path for a prepared deploy */ var deployBasePath = '__deploy/'; /* Paths: Include all paths into deploy and excluded un
\u deploy
目录:
/*
Path: Folder path for a prepared deploy
*/
var deployBasePath = '__deploy/';
/*
Paths: Include all paths into deploy and excluded unneeded files.
*/
var deployIncludePaths = [
'**/*',
'.htaccess',
'!{__deploy,__deploy/**}',
'!{.git,.git/**}',
'!assets/{js-sources,js-sources/**}',
'!assets/{scss,scss/**}',
'!assets/{vendor,vendor/**}',
'!{node_modules,node_modules/**}',
'!{panel,panel/**}',
'!thumbs/**',
'!.bowerrc',
'!.gitignore',
'!.gitmodules',
'!bower.json',
'!composer.{json,lock}',
'!gulpfile.js',
'!package.json',
'!readme.md'
];
gulp.task('deploy-copy', ['deploy-cleanup', 'css', 'js'], function() {
return gulp.src(deployIncludePaths)
.pipe(gulp.dest(deployBasePath));
});
这将把项目文件复制到\uu deploy
目录,并排除所有的gulp、bower、composer配置文件以及SCSS和JS源。它调用的deploycleanup
任务只是清理部署目录
问题: 项目代码中有一部分使用文件修改日期创建站点地图等。不幸的是,此行为无法更改 因此,如果有一种方法可以像上述任务那样复制文件,但同时保留所有文件的修改日期(或至少保存指定目录中的文件),这将非常有用。
有办法做到这一点吗?你可以用
吞下更新的来实现
下面是它的例子:
var gulp = require('gulp');
var newer = require('gulp-newer');
var imagemin = require('gulp-imagemin');
var imgSrc = 'src/img/**';
var imgDest = 'build/img';
// Minify any new images
gulp.task('images', function() {
// Add the newer pipe to pass through newer images only
return gulp.src(imgSrc)
.pipe(newer(imgDest))
.pipe(imagemin())
.pipe(gulp.dest(imgDest));
});
gulp.task('default', function() {
gulp.watch(imgSrc, ['images']);
});
因为我也需要这个,但找不到任何合适的,所以我已经编写了插件来实现它
例如:
var gulp = require('gulp');
var preservetime = require('gulp-preservetime');
gulp.task('default', function() {
gulp.src('./src/**/*')
.pipe(gulp.dest('./dest'))
.pipe(preservetime());
});
这仍然是个问题吗?我翻遍了源代码,肯定没有启用此功能的选项,但是我没有看到它更新修改时间的任何明确位置。我假设这是某个库的默认行为。听起来像是需要创建类似于gulp.dest()
的东西,以确保修改的时间不会更改。是的,我仍然希望能够在保留修改时间戳的同时复制文件。