Ensure you have
yarnin the root of the repository to get the dependencies.
- Create a
src/features.jsfile (you can copy the sample) containing the features that you want polyfilled. You can take a look at polyfill.io's docs for the available options.
- Create a
Now you can run
yarn start to start a local server at
serverless-env.yml and fill in the relevant information. Below are the explanation for the options:
bucket.name- any name unique to S3. Nothing actually gets stored in here, it's just used as the origin for CloudFront
distribution.alias- the domain that will be used for the CloudFront distribution (presumably something like
distribution.cert-arn- the ARN of an AWS Certificate Manager certificate that matches the alias (as in, as certificate for
With the config in place, install
serverless by running
npm install -g serverless. You can then run
sls deploy --aws-profile [PROFILE] to deploy the lambda function, S3 bucket, and CloudFront distribution.
Once everything has been deployed, you can associate the CloudFront distribution with your domain through AWS Route53 by creating an alias record for the appropriate hosted zone. Then you can include script tag like the below to conditionally load only the correct polyfills:
Bug reports and pull requests are welcome on GitHub at https://github.com/CultureHQ/polyfill-lambda.
The code is available as open source under the terms of the MIT License.