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

ww-webpack-s3-uploader

v1.4.1

Published

Uploads compiled assets to s3 during webpack build

Downloads

3

Readme

S3 Uploader for Webpack

Build Status

This will upload all compiled assets to AWS S3 bucket during a webpack build process. You can serve all your files via Cloud Front or different CDN.

Installation

$ npm i -S webpack-s3-uploader

How to use it

First set environmental variables:

AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY

Essential webpack configuration

// require plugin 
var S3Uploader = require('webpack-s3-uploader')


const config = {
  context: path.resolve(__dirname, '..'),

  output: {
    path: path.resolve(__dirname, '../build/public/assets'),
    publicPath: 'your_cdn_url',
  },

  plugins: [
    new S3Uploader({
      s3Options: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
        region: 'us-west-1',
        sessionToken: 'asdsaad' // the optional AWS session token to sign requests with
      },
      s3UploadOptions: {
        Bucket: 'MyBucket'
      },
    })
  ]
  // ..other configuration
}

It is required to set:

  • output.path is a path, where all assets will be compiled and those will be uploaded. You can use exclude and include option.
  • output.publicPath it is a path, where all compiled assets will be referenced to. During a compilation process webpack replaces local path with this one. If you have Cloud Front pointed to your S3 bucket, you should put url here.

Options

  • exclude: A Pattern to match for excluded content (e.g. /.*\.(css|js)/). Behaves similarly to webpack's loader configuration.
  • include: A Pattern to match for included content. Behaves the same as the exclude.
  • s3Options: Provide keys for upload extention of s3Config
  • s3UploadOptions: Provide upload options putObject
  • basePath: Provide the namespace where upload files on S3
  • progress: Enable progress bar (defaults true)
  • additionalFiles: List of additional files for upload:
new S3Uploader({
  // ...
  additionalFiles: [
    {
      // full path to file
      path: '/usr/home/my-repo/static/icons/icon.svg',
      // s3 file url
      name: 'icons/icon.svg',
    }
  ]
});
Advanced include and exclude rules

include and exclude rules behave similarly to Webpack's loader options. In addition to a RegExp you can pass a function which will be called with the path as its first argument. Returning a truthy value will match the rule. You can also pass an Array of rules, all of which must pass for the file to be included or excluded.

Pathing for resources outside of output.path

Resources that are located outside of the webpack output.path directory are pathed as follows

output.path = /myproject/build/dist/bundle
const ASSET_OUTPUT_PATH =/myproject/build/assets

or

const ASSET_OUTPUT_PATH =../assets

...

rules [
  use: [
    ...,
    {
      loader: 'file-loader',
      options: {
        ...,
        outputPath: ASSET_OUTPUT_PATH
      }
    }
]

The above configuration will output to the local file system as follows

build
|
----- dest
      |
       ---- bundle.js
|
----- assets
      |
       ---- myasset.png

and will be pathed in S3 as follows

my-bucket
|
---- bundle.js
---- assets
     |
      ---- myasset.png
Acknowledgements

This is a lite and refactored version of s3-plugin-webpack