我是新来的。我正在使用gulp任务来执行AWS发布。在发布之前,我想重命名所有没有扩展名的html文件(即删除扩展名)。
然后使用两个不同的标题发布内容,以强制HTML文件的内容类型为“text / html”。
由于我已经删除了.html文件扩展名,因此无法根据任何条件找到发布条件。
下面的代码删除了html扩展名,但不根据文件类型添加不同的标头。如何根据文件类型管道publisher.publish(htmlHeaders)或publisher.publish(normalHeaders)?
gulp.task('aws-staging-main', function () {
var publisher = awspublish.create(
{
region: "us-east-1",
params: {
Bucket: "<my bucket>"
},
accessKeyId: "<my access key>",
secretAccessKey: "<my secret access key>"
}
);
var normalHeaders = {
"Cache-Control": "max-age=315360000, no-transform, public",
};
var htmlHeaders = {
"Cache-Control": "max-age=315360000, no-transform, public",
'Content-Type': 'text/html; charset=utf-8'
};
var cfSettings = {
distribution: '<my distribution>',
accessKeyId: "<my key>",
secretAccessKey: "<my secret key>",
wait: true,
originPath: '/dist',
}
return (
gulp.src(Paths.DIST_ALL)
.pipe(rename(function (path){
if( path.extname === '.html')
path.extname = "";
}))
.pipe(publisher.publish(normalHeaders));
.pipe(cloudfront(cfSettings))
.pipe(awspublish.reporter())
);
})
为了使这个工作,我做了两个不同的gulp.src分别采购HTML文件和其他文件,然后使用“merge2”合并它们,如下所示。
var StreamAllExclHtml=gulp.src([Paths.DIST_ALL,Paths.DIST_ALL_NOT_HTML])
.pipe(publisher.publish(normalHeaders));
var StreamHtml=gulp.src(Paths.DIST_HTML)
.pipe(rename(function (path) {
if (path.basename != "index") {
path.extname = "";
}
}))
.pipe(publisher.publish(htmlHeaders));
return(
merge(StreamAllExclHtml,StreamHtml)
.pipe(publisher.sync('',whitelist.whitelist))
.pipe(cloudfront(cfSettings))
.pipe(awspublish.reporter())
)