设置就像这样简单:
gulp.task('rev-js', function() {
return gulp.src('/js/main.js, {base: '.'})
.pipe(newer('_build'))
.pipe(rev())
.pipe(gulp.dest('_build'))
.pipe(rev.manifest())
.pipe(gulp.dest('_build/rev/js'));
});gulp-newer显然不能在这里工作,因为目标文件有一个不同的名字。在这种情况下,有没有什么变通办法让gulp newer(或gulp changed)工作?
发布于 2015-08-06 17:43:05
在gulp-较新的options文档中,我读到它支持传入配置对象而不是目的地。在configuration对象中,您可以指定从旧文件到新文件映射函数。因此,不是
newer('_build')你可以写
newer({dest: '_build', map: mappingFn})映射函数接受文件的相对名称,并期望它返回转换后的名称-请参阅index.js文件。您可以定义一个函数,该函数使用以前生成的rev-manifest.json清单来查找正确的文件名。我在您的构建脚本(未测试)中添加了以下内容:
gulp.task('rev-js', function() {
// get the existing manifest
// todo: add logic to skip this if file doesn't exist
var currentManifest = JSON.parse(fs.readFileSync('rev-manifest.json', 'utf8'));
// mapping function for gulp-newer
function mapToRevisions(relativeName) {
return currentManifest[relativeName]
}
return gulp.src('/js/main.js, {base: '.'})
.pipe(newer({dest: '_build', map: mapToRevisions}))
.pipe(rev())
.pipe(gulp.dest('_build'))
.pipe(rev.manifest())
.pipe(gulp.dest('_build/rev/js'));
});发布于 2015-10-10 04:28:58
我建议您使用gulp-newy,您可以在自己的函数中操作路径和文件名。然后,只需使用该函数作为newy()的回调。这使您可以完全控制要比较的文件。
这将允许1:1或多对1比较。
newy(function(projectDir, srcFile, absSrcFile) {
// do whatever you want to here.
// construct your absolute path, change filename suffix, etc.
// then return /foo/bar/filename.suffix as the file to compare against
}

https://stackoverflow.com/questions/31638330
复制相似问题