在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):smysnk/gulp-cloudfront开源软件地址(OpenSource Url):https://github.com/smysnk/gulp-cloudfront开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-cloudfront
PurposeContent distribution networks like CloudFront let you cache static assets in Edge Locations for extended periods of time. A problem occurs however when you go to release a new version of your website, you will have to explictly tell CloudFront to expire each file or you will have to wait for the TTL to expire. In the case of CloudFront, you will need to invalidate items or wait for the cache TTL to expire before vistors of your website will see the vew version. A solution to this problem is adding a revisioned suffix to the filename for each static asset. The gulp plugin gulp-rev-all can assist in this process. eg. unicorn.css => unicorn-098f6bcd.css You can then use gulp-s3 to upload the revisioned files to a S3 bucket which CloudFront points to. Finally gulp-cloudfront comes in during the final step, to update a CloudFront distributions' Default Root Object to the latest revisioned index.html. You can in essence host multiple versions of your website under the same static host and if you need to revert to an older version you need only change the index.html file. Under the HoodThis plugin will identify the index.html file based on the default or configured pattern. Once identified it will update the CloudFront distribution to the new index file. InstallInstall with npm
Examplevar gulp = require('gulp');
var revall = require('gulp-rev-all');
var awspublish = require('gulp-awspublish');
var cloudfront = require("gulp-cloudfront");
var aws = {
"key": "AKIAI3Z7CUAFHG53DMJA",
"secret": "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",
"bucket": "bucket-name",
"region": "us-standard",
"distributionId": "E1SYAKGEMSK3OD"
};
var publisher = awspublish.create(aws);
var headers = {'Cache-Control': 'max-age=315360000, no-transform, public'};
gulp.task('default', function () {
gulp.src('dist/**')
.pipe(revall())
.pipe(awspublish.gzip())
.pipe(publisher.publish(headers))
.pipe(publisher.cache())
.pipe(awspublish.reporter())
.pipe(cloudfront(aws));
}); APIoptions.patternIndexType: Specify the pattern used to match the default root object var aws = {
..,
"patternIndex": /^\/root\-[a-f0-9]{4}\.html(\.gz)*$/gi
}; License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论