gulp task plugin for mgechev/angular-seed that gzips and publishes angular app to s3 with CloudFront invalidations
If you would like to learn how to setup an Anuglar2 app on S3+CloudFront with a free SSL cert read my blog post TODO: add blog post
- Clone this repo, and copy
task/awspublish.tsyour angular-seed projectstools/tasks/projectdir. Simlinks do not work and are not advised. - Run
npm install --save-dev gulp-awspublish merge-stream concurrent-transform gulp-cloudfront-invalidate-aws-publish - In your
tools/config/project.config.tsadd the following before yourconstructor(). Add another index for each of your stages at the same level asprodbelow:
PUBLISH_TASK_CONFIG: any = {
prod: {
awsProfile: 'alayna-page', //Can use AWS_PROFILE env var instead (AWS_PROFILE=alayna-page gulp awspublish)
patternsToGzip: ['**/*.js', '**/*.css', '**/*.html'],
patternsToOmit: [], //By default won't omit anything (will upload entire dist/prod dir
s3: { //@see http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
params: {
Bucket: 'www.alaynapage.org'
}
},
headers: {}, //Headers to add to all objects
cf: { //@see https://github.com/lpender/gulp-cloudfront-invalidate-aws-publish
distribution: 'E2A654H2YRPD0W'
}
},
};- In your
package.jsonadd an entry for each of your stages in thescriptssection:
"scripts": {
"awspublish.prod": "gulp awspublish --color --build-type prod --awspublish-stage prod",
"awspublish.staging": "gulp awspublish --color --build-type prod --awspublish-stage staging",
}- Build your Angular app via normal angular-seed process (ex:
npm run build.prod.exp). Then run your publish task. Ex:gulp awspublish.prod
--awspublish-stagedictates which stage index ofPUBLISH_TASK_CONFIGto use.- By default all assets in
dist/prodwill be uploaded to s3 withpublic-readpermissions. - awsProfile: The AWS SDK profile to use when uploading to S3 and invalidating CF objects. See the AWS SDK config guide
- patternsToGzip:
gulp.srcpatterns to gzip, relative to the angular-seeddist/proddir. Default:['**/*.js', '**/*.css', '**/*.html'] - patternsToOmit:
gulp.srcpatterns to not upload to s3, relative to the angular-seeddist/proddir. By defaultdist/prod/**/*will be uploaded (after gzip). - s3: The AWSConfig object used to create an aws-sdk S3 client. At a minimum you must specify
bucket, to define the site bucket. You can find all available options in the []AWS SDK documentation](//@see http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property) - headers: Headers to add to all objects in S3. By default you will get
'Cache-Control': 'max-age=315360000, no-transform, public' - cf: CloudFront distro id must be defined in
cf.distribution. This will create CF invalidations for all uploaded resources. See gulp-cloudfront-invalidate-aws-publish
mgechev/angular-seed, gulp-awspublish and gulp-cloudfront-invalidate-aws-publish