Skip to content

Commit

Permalink
feat: version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zenotsai committed Feb 16, 2022
1 parent 93f8a3f commit 7a1502a
Show file tree
Hide file tree
Showing 32 changed files with 2,390 additions and 1,334 deletions.
14 changes: 10 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"env": {
"jest": true
},
"extends": ["@antfu"],
"plugins": ["jest"],
"rules": {}
}
"extends": [
"@antfu"
],
"plugins": [
"jest"
],
"rules": {
"space-before-function-paren": 0
}
}
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

133 changes: 83 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,96 @@
# unplugin-starter
# unplugin-upload-cdn

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

Starter template for [unplugin](https://github.com/unjs/unplugin).

## Template Usage

To use this template, clone it down using:
Upload resource files to cdn. Powered by unplugin.

# Install
```bash
npx degit antfu/unplugin-starter my-unplugin
npm i unplugin-upload-cdn
```

And do a global replace of `unplugin-starter` with your plugin name.

Then you can start developing your unplugin 🔥
# Provider
Support Tencent cos, Alibaba oss

To test your plugin, run: `pnpm run dev`
To release a new version, run: `pnpm run release`
[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";

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

```bash
npm i unplugin-starter
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 Starter from 'unplugin-starter/vite'
import { unpluginUploadCDN, COS } from "unplugin-upload-cdn";

export default defineConfig({
plugins: [
Starter({ /* options */ }),
unpluginUploadCDN.vite({
/* options */
}),
],
})
```
Expand All @@ -48,11 +104,13 @@ Example: [`playground/`](./playground/)

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

export default {
plugins: [
Starter({ /* options */ }),
unpluginUploadCDN.rollup({
/* options */
}),
],
}
```
Expand All @@ -64,45 +122,20 @@ export default {
<summary>Webpack</summary><br>

```ts

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

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

<br></details>

<details>
<summary>Nuxt</summary><br>

```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-starter/nuxt', { /* options */ }],
],
}
```

> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
<br></details>

<details>
<summary>Vue CLI</summary><br>

```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-starter/webpack')({ /* options */ }),
],
},
}
```

<br></details>
8 changes: 7 additions & 1 deletion examples/rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"license": "ISC",
"dependencies": {
"globby": "9.2",
"rollup": "^2.56.3"
"log-symbols": "^5.1.0",
"ora": "5.4.1",
"rollup": "^2.56.3",
"unplugin-upload-cdn": "0.1.0"
},
"devDependencies": {
"@rollup/plugin-babel": "^5.3.0"
}
}
18 changes: 4 additions & 14 deletions examples/rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import demo, { COS } from "../../dist/index";

const cos = new COS({
Bucket: "demo-1256203566",
Region: "ap-nanjing",
SecretId: "AKID72hcHhUoX2sTv7Ho35dkmV0OhUDieyxh",
SecretKey: "sVxDFqDQO7iCWgeP0SfWLwNadWE2b0AC",
cosBaseDir: "demo",
projectDir: "aaaa",
existCheck: true,
});
// import demo, { COS } from "unplugin-upload-cdn";
import { unpluginUploadCDN, COS } from "unplugin-upload-cdn";

export default {
input: "src/main.js",
Expand All @@ -17,10 +8,9 @@ export default {
format: "cjs",
},
plugins: [
demo.rollup({
provider: cos,
ignore: ["!**/a.js"],
unpluginUploadCDN.rollup({
dir: "dist",
provider: cos,
}),
],
};
Loading

0 comments on commit 7a1502a

Please sign in to comment.