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-upload-cdn-plugin

v2.0.1

Published

Upload your webpack-generated assets to CDN, allowing renaming/rehashing.

Downloads

3

Readme

webpack-upload-cdn-plugin

fork 过来修改了几个问题

1、create-react-app 下路径替换错误问题

2、支持在文件上传失败时中断打包流程

npm status

Upload your webpack-generated assets to CDN, allowing renaming/rehashing.

Requirements & Important Notes

  • Node 8+ (which supports async/await) is required recommanded.

  • This plugin has NOT been tested on Windows platform.

  • This plugin supports webpack@4 ONLY.

Webpack Configuration

  • process.env.NODE_ENV OR options.mode: this plugin only works in production mode.

  • output.publicPath: we only support / or empty string (for simplicity).

  • optimization.minimize: false is preferred if your CDN provider can do compressing work.

Installation

npm install -D webpack-upload-cdn-plugin

# or
yarn add --dev webpack-upload-cdn-plugin

Demo

Usage

const WebpackCDNPlugin = require('webpack-upload-cdn-plugin')

module.exports = {
  // ... other fields
  plugins: [
    // ...other plugins
  ]
}

if (process.env.NODE_ENV === 'production') {
  const cdnPlugin = new WebpackCDNPlugin({
    // whether to keep generated files (on local fs), default: `false`
    keepLocalFiles: false,
    // whether to keep generated sourcemaps, default: `false`
    keepSourcemaps: false,
    // whether to backup html files (before replaced), default: `false`
    backupHTMLFiles: true,
    // manifest file name (`String | false`)
    manifestFilename: 'manifest.json',

    errorOnUploadFail: false,

    // a function, which returns `Promise<url>`
    // you can do your compressing works with content
    // `params.content`: `String | Buffer`
    // `params.extname`: file extension
    // `params.file`: original file (with path)
    uploadContent({ content, extname, file }) {
      /**
       * Return falsy value means that you want to KEPP the
       * file as it is. This usually happens with certain
       * file types, which may not be supported by your CDN
       * provider, or must be under the same origin with your
       * HTML files(for example, files like `.wasm` that
       * should be loaded by `fetch` or `XMLHttpRequest`).
       *
       * !!! Note !!!
       * Be CAREFUL with media resources (especially images).
       * When you are using an image in your CSS file, while
       * deciding not to upload that it(the image), it CAN lead
       * to an unexpected `404 (Not Found)` ERROR.
       */
      if (['ico', 'txt', 'wasm'].includes(extname)) {
        return false
      }

      // You can also implement your own cache here
      const hash = md5(content)
      if (youCache.has(hash)) {
        return youCache.get(hash)
      }

      return require('your-cdn-provider').uploadContent({
        content: content,
        fileType: getFileType(extname)
      })
      // for testing
      // const hash = (Math.random() ).toString(16).split('.')[1]
      // return Promise.resolve(`https://cdn.example.com/${hash}.${extname}`)
    }
  })

  module.exports.plugins.push(cdnPlugin)
}