Package and deploy any frontend with your serverless backend.
npm install --save-dev serverless-frontend-plugin
- Include this plugin in the
plugins
section of yourseverless.yml
.
plugins:
- serverless-frontend-plugin
- Add your frontend build commands and set the working directory by adding the following to the
custom
section of yourserverless.yml
:
custom:
serverless-frontend-plugin:
distDir: frontend/dist
build:
cwdDir: frontend
command:
- npm
- run
- build
distribution:
acmCertificateArn: <your certificate arn>
dnsName: <your-domain.com> # Route53 record value
altDnsName: <another.your-domain.com> # Route53 record value
hostedZoneName: <your-domain.com> # Route53 Hosted Zone Name
mode
: (string) Type of frontend hosting. Currently the only supported mode iscloudfront
.distDir
: (string) The directory that gets uploaded and hosted as a static site. Defaults tofrontend/dist
.build
: (Map)command
: (string[]) Command and options as an array of strings. For example,["npm", "run", "build"]
Defaults to["echo", "no", "frontend", "build", "command"]
.cwdDir
: (string) The directory from which to run thebuild.command
. Defaults to./frontend
.env
: (Map) A key/value mapping of environment variables and values to inject into the frontend build.
stackName
: (string) Name of the CloudFormation stack for the frontend. Defaults to<service-name>-<stage>-<region>
.bucket
: (Map)name
: (string) Name of the S3 Bucket to upload thedistDir
to. Defaults to a generated name.indexDocument
: (string) Defaults toindex.html
.errorDocument
: (string) Defaults toindex.html
.
distribution
: (Map)dnsName
: (string Required) A DNS name to use for this Cloudfront distribution. This is required and has no default values.altDnsName
: (string) Another DNS name to use for this Cloudfront distribution.acmCertificateArn
: (string, Required) AWS ACM Certificate Arn that covers the domain names listed inaliases
.hostedZoneName
: (string) Name of the AWS Route53 Hosted Zone to create the Route53 records. Defaults to the value ofdnsName
.mimeTypes
: (Map) A key/value mapping of file extensions and mime types to override. For example:
... distribution: mimeTypes: html: text/html # default
offline
: (Map)command
: (string[]) Command and options as an array of strings. For example,["npm", "start"]
Defaults to["echo", "no", "frontend", "offline", "command"]
.env
: (Map) A key/value mapping of environment variables and values to inject into the frontend start command.cwdDir
: (string) The directory from which to run theoffline.command
. Defaults to./frontend
.
This plugin seamlessly integrates with serverless-offline
. Simply Add an offline
configuration under custom.serverless-frontend-plugin
in your serverless.yml
. See offline
options above.
See the test configs on Github for working examples. Just be sure to replace the following section in the serverless.yml
:
# Replace this
plugins:
- ../../../index.js
# With this
plugins:
- serverless-frontend-plugin