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

webpack-oss-plugin-cjs

v0.9.3

Published

Uploads compiled assets to oss after build

Downloads

2

Readme

Fork from https://github.com/waijule/webpack-oss-plugin

Transform native ES module to commonjs to remove Webpack and Babel dependencies

$ npm i webpack-oss-plugin-cjs  --save-dev
// webpack.config.js

const OSSPlugin = require('webpack-oss-plugin-cjs')

module.exports = {
    // ...
    plugins: [
        new OSSPlugin({

            // Exclude uploading of html, 
            exclude: /\.html$/,

            // Include option, also
            // include: /\.(js|css)$/,

            // ossOptions are required
            ossOptions: {
                accessKeyId: 'your id',
                accessKeySecret: 'your secret',
                region: 'your region',
                bucket: 'your bucket',
            }
        })
    ]
}

The following is origin document from https://github.com/waijule/webpack-oss-plugin :

OSS Plugin

Travis Badge

This plugin will upload all built assets to OSS

Install Instructions

$ npm i webpack-oss-plugin

Note: This plugin needs NodeJS > 0.12.0

Usage Instructions

I notice a lot of people are setting the directory option when the files are part of their build. Please don't set directory if your uploading your build. Using the directory option reads the files after compilation to upload instead of from the build process.

Require webpack-oss-plugin

You will need babel-polyfill to use this plugin

var OSSPlugin = require('webpack-oss-plugin')
With exclude
var config = {
  plugins: [
    new OSSPlugin({
      // Exclude uploading of html
      exclude: /.*\.html$/,
      // ossOptions are required
      ossOptions: {
        accessKeyId: process.env.OSS_ACCESS_KEY,
        accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
        region: 'oss-cn-shanghai',
        bucket: process.env.OSS_BUCKET,
      },
      ossUploadOptions: {
      }
    })
  ]
}
With include
var config = {
  plugins: [
    new OSSPlugin({
      // Only upload css and js
      include: /.*\.(css|js)/,
      // ossOptions are required
      ossOptions: {
        accessKeyId: process.env.OSS_ACCESS_KEY,
        accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
        region: 'oss-cn-shanghai',
        bucket: process.env.OSS_BUCKET,
      },
      ossUploadOptions: {
      }
    })
  ]
}
With basePathTransform
import gitsha from 'gitsha'

var addSha = function() {
  return new Promise(function(resolve, reject) {
    gitsha(__dirname, function(error, output) {
      if(error)
        reject(error)
      else
       // resolve to first 5 characters of sha
       resolve(output.slice(0, 5))
    })
  })
}

var config = {
  plugins: [
    new OSSPlugin({
      ossOptions: {
        accessKeyId: process.env.OSS_ACCESS_KEY,
        accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
        region: 'oss-cn-shanghai',
        bucket: process.env.OSS_BUCKET,
      },
      ossUploadOptions: {
      }
      basePathTransform: addSha
    })
  ]
}


// Will output to /${mySha}/${fileName}
With Dynamic Upload Options
var config = {
  plugins: [
    new OSSPlugin({
      ossOptions: {
        accessKeyId: process.env.OSS_ACCESS_KEY,
        accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
        region: 'oss-cn-shanghai',
        bucket: process.env.OSS_BUCKET,
      },
      ossUploadOptions: {
        headers(fileName) {
          return {
            'Cache-Control': 'max-age=31536000'
          };
        },
      }
    })
  ]
}

Options

  • exclude: Regex to match for excluded content
  • include: Regex to match for included content
  • overwrite: false will skip uploading if file already exists in oss. Default true
  • ossOptions: Provide keys for upload extention of ossConfig
  • ossUploadOptions: Provide upload options put
  • basePath: Provide the namespace where upload files on OSS
  • basePathTransform: transform the base path to add a folder name. Can return a promise or a string

Contributing

All contributions are welcome. Please make a pull request and make sure things still pass after running npm run test For tests you will need to either have the environment variables set or setup a .env file. There's a .env.sample so you can cp .env.sample .env and fill it in. Make sure to add any new environment variables.

Commands to be aware of

WARNING: The test suit generates random files for certain checks. Ensure you delete files leftover on your Bucket.
  • npm run test - Run test suit (You must have the .env file setup)
  • npm run build - Run build

Publish

  • npm run prep:patch - Prepare for patch release
  • npm run prep:minor - Prepare for minor release
  • npm run prep:major - Prepare for major release Push a tag will automatically publish a version to NPM by travis

Thanks

Thanks to s3-plugin-webpack