webpack4-cdn-plugin

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 webpack4-cdn-plugin
# or
yarn add --dev webpack4-cdn-plugin
Demo
Usage
const WebpackCDNPlugin = require('webpack4-cdn-plugin')
module.exports = {
plugins: [
]
}
if (process.env.NODE_ENV === 'production') {
const cdnPlugin = new WebpackCDNPlugin({
keepLocalFiles: false,
keepSourcemaps: false,
backupHTMLFiles: true,
manifestFilename: 'manifest.json',
assetMappingVariable: 'webpackAssetMappings',
uploadContent({ content, extname, file }) {
if (['ico', 'txt', 'wasm'].includes(extname)) {
return false
}
const hash = md5(content)
if (youCache.has(hash)) {
return youCache.get(hash)
}
return require('your-cdn-provider').uploadContent({
content: content,
fileType: getFileType(extname)
})
}
})
module.exports.plugins.push(cdnPlugin)
}