A lightweight CDN sync plugin for initx.
Upload local static assets to Tencent Cloud COS with interactive selection, diff checks, and multi-target support.
npm i -g initxpnpm add initx-plugin-cdn-sync -DCreate cdn.config.ts:
import { defineConfig } from 'initx-plugin-cdn-sync'
export default defineConfig({
sourceDir: 'src/static',
clients: {
cos: {
default: {
bucket: 'your-bucket-name',
region: 'ap-guangzhou',
cdnUrl: 'https://cdn.example.com',
basePath: '/static'
}
}
}
})# upload changed files in git (default)
ix cdn- Upload a single file or a full directory
- Upload changed files from Git (default mode)
- Upload image files from a specific commit or commit range
- Optional cloud content diff check with
--diff - Multi-target uploads with
--target - Restore deleted/renamed-away files from commit history with
--revert
Current implementation supports Tencent Cloud COS upload.
# single file
ix cdn ./src/static/logo.png
# directory
ix cdn ./src/static
# changed files in git (default)
ix cdn
# commit
ix cdn 9a1f6c9867e7b87444bab52eeb0a6ebe28059265
# commit range
ix cdn 4b25720...15ebc15
# specify target
ix cdn --target prod
# enable diff check
ix cdn --diff
# restore from deleted entries in commit/range
ix cdn main...HEAD --revertIf credentials are not configured, the plugin prompts during upload.
Pre-configure credentials:
ix cdn configYou can store multiple profiles (for example default, prod, test) and reference them in config.
Profile resolution order:
clients.<type>.<client>.profile > targets.<name>.profile > default
import { defineConfig } from 'initx-plugin-cdn-sync'
export default defineConfig({
sourceDir: 'src/static',
clients: {
cos: {
default: {
bucket: 'cos-default-bucket',
region: 'ap-guangzhou',
cdnUrl: 'https://cdn.example.com',
basePath: '/static',
profile: 'default'
}
}
},
targets: {
prod: {
type: 'cos',
client: 'default',
override: { basePath: '/static/prod' }
},
test: {
type: 'cos',
client: 'default',
override: { basePath: '/static/test' }
}
}
})pnpm install
pnpm stub
pnpm lint
pnpm tsc --noEmit