0.1.0 • Published 2 years ago

unplugin-upload-cdn v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

unplugin-upload-cdn

NPM version

Upload resource files to cdn. Powered by unplugin.

Install

npm i unplugin-upload-cdn

Provider

Support Tencent cos, Alibaba oss

COS Document OSS Document

import { unpluginUploadCDN, COS, OSS } from "unplugin-upload-cdn";

const cos = new COS({ /* options */ });
const oss = new OSS({ /* options */ });

import { unpluginUploadCDN, COS } from "unplugin-upload-cdn";

export default defineConfig({
  plugins: [
    unpluginUploadCDN.vite({
     /* options */
     provider: cos // oss,
    }),
  ],
})

The parameters of the environment variables are read by default

OSS

{
  accessKeyId: process.env.CDN_PLUGIN_ACCESSKEY_ID,
  accessKeySecret: process.env.CDN_PLUGIN_SECRET,
  bucket: process.env.CDN_PLUGIN_BUCKET,
  region: process.env.CDN_PLUGIN_REGION,
}

COS

{
  SecretId: process.env.CDN_PLUGIN_SECRET_ID,
  SecretKey: process.env.CDN_PLUGIN_SECRET_KEY,
  Bucket: process.env.CDN_PLUGIN_BUCKET,
  Region: process.env.CDN_PLUGIN_REGION,
}

Custom

implements IProvider

export interface IProvider {
  upload: (file: IFile) => void
  beforeUpload: (files: IResource[], existCheck?: boolean) => Promise<IResource[]>
}
NameEnvironment VariablesDefaultDescription
ignoreCDN_PLUGIN_IGNORE[]ignore uploaded files, e.g. "*/.html"
dirnullUploaded directory
existCheckCDN_PLUGIN_EXISTCHECKnullcheck if the file has been uploaded, judged by the file name
prefixnullpackage.json.nameprefix
useVersionCDN_PLUGIN_USE_VERSIONfalsesplice the version of package.json as a prefix
provider-null-

Options

// vite.config.ts
import { unpluginUploadCDN, COS } from "unplugin-upload-cdn";

export default defineConfig({
  plugins: [
    unpluginUploadCDN.vite({
     /* options */
    }),
  ],
})

Example: playground/

// rollup.config.js
import { unpluginUploadCDN, COS } from "unplugin-upload-cdn";

export default {
  plugins: [
     unpluginUploadCDN.rollup({
      /* options */
    }),
  ],
}

const { unpluginUploadCDN, COS } = require("unplugin-upload-cdn");

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    unpluginUploadCDN.webpack({
      /* options */
    }),
  ]
}