webpack5-cdn-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

webpack5-cdn-plugin

For webpack4, please refer to webpack4-cdn-plugin.

Docs

Install

npm i webpack5-cdn-plugin -D

Usage

const { Webpack5CDNPlugin } = require('webpack5-cdn-plugin')

let cacheData = null;

// webpack config
module.exports = {
  plugins: [
    // ...
    new Webpack5CDNPlugin({
      keepLocalFiles: false,
      manifestFilename: 'manifest.json',
      uploadContent({ file, extname, content }) {
        // TODO 需要自己实现上传文件、重试、并发控制
        const hash = md5(content);
        
        if (cache[hash]) {
          return cache[hash]
        }

        return uploadTaskManager.upload(content).then(result => {
          cache[hash] = result.url
          return `http://127.0.0.1:8080/${result.url}`
        })
      },
      before() {
        cacheData = readCache();
      },
      done() {
        persistCache(cacheData);
      }
    })
  ]
}

Readme

Keywords

Package Sidebar

Install

npm i webpack5-cdn-plugin

Weekly Downloads

1

Version

0.0.9

License

MIT

Unpacked Size

28.1 kB

Total Files

11

Last publish

Collaborators

  • wemlion