99x / serverless-react-boilerplate

A serverless react boilerplate for offline development

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Frontend gulp task to publish to S3

mjzone opened this issue · comments

Hi! We would like to help. How about using https://github.com/pgherveou/gulp-awspublish ?

Sure. That plugin looks good. Go ahead @mhrisse 🎇

Hi! There is also https://github.com/serverless/serverless-client-s3 which is on the original serverless repo, but does not work with v1.0 properly yet. It looks very simple, maybe the way to go? @mjzone

@mhrisse Since it is not properly supported let's go with gulp-awspublish.
It's great if we could write a gulp task accepting APIG uri as a parameter and replace the BASE_URL in the react app and then do the bundling and upload to S3.
As the next step of automation, we can configure cloudfront to avoid cross origin requests and have a relative base url for the client. Then we can use a proxy such that we don't have to change api urls between development and production.

If you check my edited gulpfile, https://github.com/99xt/serverless-react-boilerplate/blob/react-authenticate/gulpfile.js, I added a couple very simple tasks that webpack the app and sync to an s3 bucket using the AWS CLI. See tasks deploy-web, build-web, and sync-web-s3

It copies a webpack.[stage].config.js to webpack.config.js first so you can set up a different config for each environment.

What I haven't done yet is create a way to change s3 buckets per stage, a simple conditional would suffice, but having point to env variables would be more elegant.