npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-plugin-s3-travisbloom

v0.3.2

Published

Enables you to deploy your gatsby site to a S3 bucket.

Downloads

5

Readme

gatsby-plugin-s3

Enables you to deploy your gatsby site to a S3 bucket.
Requires very little configuration, while optimizing your site as much as possible.

Features:

  • 📦 Fully handles the deployment process for you, all you need to configure is your bucket name.
    • Automatically creates/updates bucket with optimal configuration applied.
    • Syncs gatsby files to the bucket & updates metadata.
  • ⏭ Redirects.
  • 💾 Optimizes caching for you.
  • ☁️ Optional serverless framework support if you want to take things a step further.
  • ✏️ Add your own params to uploaded S3 objects (if you wish).

Usage

Install the plugin:

npm i gatsby-plugin-s3

Add it to your gatsby-config.js & configure the bucket name (required)

plugins: [
  {
      resolve: `gatsby-plugin-s3`,
      options: {
          bucketName: 'my-website-bucket'
      },
  },
]

There are more fields that can be configured, see below.

Add a deployment script to your package.json

"scripts": {
    ...
    "deploy": "gatsby-plugin-s3 deploy"
}

Optionally you can skip the confirmation prompt automatically by adding --yes like so:

    "deploy": "gatsby-plugin-s3 deploy --yes"

When gatsby-plugin-s3 detects a CI environment, it will automatically skip this prompt by default.

After configuring credentials (see below), you can now execute npm run build && npm run deploy to have your site be build and immediately deployed to S3.

Credentials

Globally

A couple of different methods of specifying credentials exist, the easiest one being using the AWS CLI:

# NOTE: ensure python is installed
pip install awscli
aws configure

Environment variables

If you don't want to have your credentials saved globally (i.e. you're dealing with multiple tokens on the same environment), they can be set as environment variables, for example:

AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npm run deploy

Additionally, these can be set in a local .env file too, but this requires a bit more setup work. See the recipe here.

Configuration

Recipes

Several recipes are available:

Adding environment specific settings

Learn how to retrieve AWS credentials from a .env file. Additionally setup a different bucket name depending on your environment.

Using a different content type for files

Learn how to override the content type gatsby-plugin-s3 sets on your files.

Using CloudFront with gatsby-plugin-s3

CloudFront is a global CDN and can be used to make your blazing fast Gatsby site load even faster, particularly for first-time visitors. Additionally, CloudFront provides the easiest way to give your S3 bucket a custom domain name and HTTPS support.

Using serverless with gatsby-plugin-s3

Serverless can be used in combination with gatsby-plugin-s3, swapping the plugin's deployment step for sls deploy instead.
Serverless will give you the added advantage of being able to add multiple AWS services such as Lambda, CloudFront, and more all in the same repo, deployment step and CloudFormation stack while still being able to profit from all the optimisations gatsby-plugin-s3 does.

Using a proxy

Routing traffic from gatsby-plugin-s3 during the deployment through a http proxy can be done with a env var.

Configuring a custom endpoint

Using Yandex, DigitalOcean, or any other S3-compliant storage service together with gatsby-plugin-s3

Deploying your gatsby site under a prefix in your bucket

You can deploy your site to a prefix, leaving all other data in the bucket intact. gatsby-plugin-s3 respects the pathPrefix gatsby option with no additional setup needed for this plugin, so you can follow the guide in the gatsby docs.

AWS S3 Routing Rules Limit

AWS S3 has an undocumented limit on the number of Routing Rules that can be applied to a bucket. Unfortunately this limits the number of 302 (temporary) redirects you can create. For 301 (permanent) redirects, a way to get around the limit is setting the x-amz-website-redirect-location header on an empty object. To enable this behavior, set the generateRedirectObjectsForPermanentRedirects configuration option to true.