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 🙏

© 2026 – Pkg Stats / Ryan Hefner

s3-spa-uploader

v1.0.1

Published

Upload a single page application to S3 with the right content-type and cache-control meta-data

Readme

S3 SPA Uploader

Fork of s3-spa-upload

Upload a Single Page Application (React, Angular, Vue, ...) to S3 with the right content-type and cache-control meta-data

This requires the following AWS S3 permissions (see sample CloudFormation policy template below):

  • s3:PutObject on objects in your bucket
  • s3:ListBucket on your bucket (only needed when using --delete option)
  • s3:DeleteObject on objects in your bucket (only needed when using --delete option)

Installation

To install globally:

npm install -g s3-spa-uploader

To install locally

npm install --save-dev s3-spa-uploader

Command Line Usage

Basic usage:

s3-spa-uploader dist-dir my-s3-bucket-name

The differences between s3-spa-uploader and s3-spa-upload:

  • Works with Windows file paths
  • Add MIME-type mapping

Clean-up old files

To also clean up old files, use the --delete option. This will delete all files in the bucket that are not included in the current upload (limited to the supplied prefix, see below):

s3-spa-uploader dist-dir my-s3-bucket-name --delete

Custom cache-control mapping

You can provide your desired cache-control mapping in a json file that contains a mapping from glob patterns to cache-control headers:

{
    "index.html": "no-cache",
    "*.js": "public,max-age=31536000,immutable"
}

Suppose your mapping file is called cache-control.json:

s3-spa-uploader dist-dir my-s3-bucket-name --cache-control-mapping cache-control.json

If you don't provide a custom mapping, the default will be used, which should be okay for most SPA's, see below.

Upload to a prefix

By default the SPA will be uploaded to the root of your S3 bucket. If you don't want this, specify the prefix to use:

s3-spa-uploader dist-dir my-s3-bucket-name --prefix mobile

Note that when used in conjunction with --delete, this means only old files matching that same prefix will be deleted.

Programmatic Usage

import s3SpaUploader from 's3-spa-uploader';
// const s3SpaUploader = require('s3-spa-uploader')

s3SpaUploader('dir', 'bucket').catch(console.error);

// Can supply options:
const options = {
    delete: true,
    verbose: true,
    prefix: 'mobile',
    cacheControlMapping: {
        'index.html': 'no-cache',
        '*.js': 'public,max-age=31536000,immutable',
    },
    awsCredentials: {
        accessKeyId: '...'
        secretAccessKey: '...'
        sessionToken: '...'
    },
    mimeTypeMapping: {
        ".html": "text/html",
        ".json": "application/json"
    }
}
s3SpaUploader('dir', 'bucket', options).catch(console.error);

Default Cache-Control settings

File/ext | Cache setting | Description ---------|---------------|---------- index.html|no-cache| css|public,max-age=31536000,immutable|As long as possible js|public,max-age=31536000,immutable|As long as possible png|public,max-age=86400|One day ico|public,max-age=86400|One day txt|public,max-age=86400|One day

Content-Type settings

Based on file extensions using https://www.npmjs.com/package/mime-types

You can also provide custom mime types (these have higher prioerty than the mime-types extension)

{
    ".html": "text/html",
    ".json": "application/json"
}

AWS Policy Template

This CloudFormation IAM Policy template grants the needed permissions:

- Version: "2012-10-17"
    Statement:
      - Effect: Allow # This effect is only needed when using the --delete option
          Action: s3:ListBucket
          Resource: arn:aws:s3:::your-bucket-name
      - Effect: Allow
          Action:
            - s3:DeleteObject # This action is only needed when using the --delete option
            - s3:PutObject
          Resource: arn:aws:s3:::your-bucket-name/*