@sohu-bpd/unplugin-cdn-upload
v1.0.1
Published
Upload built assets to a CDN and update asset URLs.
Readme
@sohu-bpd/unplugin-cdn-upload
Upload built assets to a private CDN storage service after the host build output is written.
Features
- supports Vite, Rollup, webpack, Rspack, and Rolldown through host-specific adapters
- uploads files from the final build output directory after the corresponding host hook runs
- filters files with
include/excluderules - excludes
**/*.htmlby default - signs
PUT Objectrequests with the SCS HMAC-SHA1 flow - keeps generated asset references unchanged
Host Support
The package root exports the unplugin factory object. In app config, prefer the host-specific subpaths:
@sohu-bpd/unplugin-cdn-upload/vite@sohu-bpd/unplugin-cdn-upload/rollup@sohu-bpd/unplugin-cdn-upload/webpack@sohu-bpd/unplugin-cdn-upload/rspack@sohu-bpd/unplugin-cdn-upload/rolldown
Rsbuild should use the /rspack entry through tools.rspack; there is no separate ./rsbuild export.
Usage
Vite
import { defineConfig } from "vite";
import cdnUpload from "@sohu-bpd/unplugin-cdn-upload/vite";
export default defineConfig({
plugins: [
cdnUpload({
bucket: "frontend-assets",
prefix: "my-app/2026-03-30",
host: "http://bjcnc.scs.sohucs.com",
accessKey: "access-key",
secretKey: "secret-key",
concurrency: 3,
include: ["assets/**"],
exclude: ["**/*.html"]
})
]
});Rollup
import cdnUpload from "@sohu-bpd/unplugin-cdn-upload/rollup";
export default {
plugins: [
cdnUpload({
bucket: "frontend-assets",
prefix: "my-app/2026-03-30",
host: "http://bjcnc.scs.sohucs.com",
accessKey: "access-key",
secretKey: "secret-key"
})
]
};Other Hosts
- Use
@sohu-bpd/unplugin-cdn-upload/webpackin webpack configs. - Use
@sohu-bpd/unplugin-cdn-upload/rspackin Rspack configs and in Rsbuild viatools.rspack.plugins. - Use
@sohu-bpd/unplugin-cdn-upload/rolldownin Rolldown configs.
Rsbuild
import cdnUpload from "@sohu-bpd/unplugin-cdn-upload/rspack";
export default {
tools: {
rspack: {
plugins: [
cdnUpload({
bucket: "frontend-assets",
prefix: "my-app/2026-03-30",
host: "http://bjcnc.scs.sohucs.com",
accessKey: "access-key",
secretKey: "secret-key"
})
]
}
}
};Options
| Name | Description | Default | Required |
| --- | --- | --- | --- |
| bucket | Bucket name. | - | Yes |
| prefix | Object key prefix. Leading and trailing / are removed. | "" | No |
| host | SCS host or origin such as bjcnc.scs.sohucs.com or http://bjcnc.scs.sohucs.com. | - | Yes |
| accessKey | Access key. | - | Yes |
| secretKey | Secret key. | - | Yes |
| include | Glob rule or glob rule list. | ["**/*"] | No |
| exclude | Glob rule or glob rule list. | ["**/*.html"] | No |
| computeMd5 | Whether to send Content-MD5. | true | No |
| concurrency | Maximum number of concurrent uploads. | 3 | No |
Behavior
Build output uploads are wired through the host adapters:
- Vite uploads after
closeBundle - Rollup and Rolldown upload after
writeBundle - webpack and Rspack upload after
afterEmit
After the relevant host finishes writing output files, the plugin scans the resolved output directory, filters files with include and exclude, and uploads matching files to:
<prefix>/<relative-output-path>The plugin does not rewrite URLs inside generated files.
During upload it prints colored, structured console logs for START, one UPLOADED line per completed upload, SUCCESS, and ERROR. Uploads run with a bounded concurrency of 3 by default unless overridden by concurrency.
