# unplugin-upload-cdn

> Plugin for uploading resource files to cdn, Powered by on unplugin

Latest version **0.1.0** (published 2022-02-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install unplugin-upload-cdn
pnpm add unplugin-upload-cdn
yarn add unplugin-upload-cdn
bun add unplugin-upload-cdn
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-02-16 |
| First published | 2022-02-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 11 |
| Unpacked size | 128.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | zenotsai |
| Keywords | unplugin, vite, webpack, rollup, cdn, upload, cos, oss |

## Links

- npm: https://www.npmjs.com/package/unplugin-upload-cdn
- Repository: https://github.com/zenotsai/unplugin-upload-cdn
- Issues: https://github.com/zenotsai/unplugin-upload-cdn/issues
- npm.io page: https://npm.io/package/unplugin-upload-cdn

## Dependencies (11)

- [ora](https://npm.io/package/ora.md) 5.4.1
- [globby](https://npm.io/package/globby.md) 9.2
- [ali-oss](https://npm.io/package/ali-oss.md) ^6.17.1
- [filesize](https://npm.io/package/filesize.md) ^8.0.7
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [unplugin](https://npm.io/package/unplugin.md) ^0.2.7
- [@types/ora](https://npm.io/package/@types/ora.md) ^3.2.0
- [log-symbols](https://npm.io/package/log-symbols.md) 4.1.0
- [@types/ali-oss](https://npm.io/package/@types/ali-oss.md) ^6.16.2
- [cos-nodejs-sdk-v5](https://npm.io/package/cos-nodejs-sdk-v5.md) ^2.11.6
- [esbuild-plugin-babel](https://npm.io/package/esbuild-plugin-babel.md) ^0.2.3

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2022-02-16

## README

# unplugin-upload-cdn

[![NPM version](https://img.shields.io/npm/v/unplugin-starter?color=a1b858&label=)](https://github.com/zenotsai/unplugin-upload-cdn)

Upload resource files to cdn. Powered by unplugin.

# Install
```bash
npm i unplugin-upload-cdn
```


# Provider
Support Tencent cos, Alibaba oss

[COS Document](https://cloud.tencent.com/document/product/436/8629)
[OSS Document](https://help.aliyun.com/document_detail/111256.html)
```js
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
```js
{
  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
```js
{
  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 
```ts
export interface IProvider {
  upload: (file: IFile) => void
  beforeUpload: (files: IResource[], existCheck?: boolean) => Promise<IResource[]>
}
```


Name | Environment Variables | Default | Description |
---  | --- | --- | --- |
ignore | `CDN_PLUGIN_IGNORE` | [] | ignore uploaded files, e.g. ["**/*.html"] |
dir |  | null | Uploaded directory |
existCheck | `CDN_PLUGIN_EXISTCHECK` | null | check if the file has been uploaded, judged by the file name |
prefix | null | package.json.name | prefix |
useVersion | `CDN_PLUGIN_USE_VERSION` | false | splice the version of package.json as a prefix |
provider | - | null | - |


# Options


<br></details>

<details>
<summary>Vite</summary><br>

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

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

Example: [`playground/`](./playground/)

<br></details>

<details>
<summary>Rollup</summary><br>

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

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

<br></details>


<details>
<summary>Webpack</summary><br>

```ts

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

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

<br></details>

---
_Source: https://npm.io/package/unplugin-upload-cdn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
