Code Monkey home page Code Monkey logo

vite-plugin-cos-upload's Introduction

文档

具体的腾讯 cos 上传方法可以查看 文档

使用 cos 上传请注意官网的注意事项:

  • Key(文件名)不能以/结尾,否则会被识别为文件夹。

  • Key(文件名)同名上传默认为覆盖操作。若您未开启版本控制且不想覆盖云上文件时,请确保上传时的Key不重复。

参数说明

interface Options {
    SecretId: string
    SecretKey: string
    Bucket: string
    Region?: string
    exclude?: RegExp
    /** 并发数 */
    concurrent?: number
    /** key 前缀 */
    prefix?: string
    /** 打包文件目录 */
    distDir?: string
    /** 是否输出日志 */
    log?: boolean
    /** cos 大文件上传方法,不传就用普通方法 */
    cosUploadFileParams?: SliceUploadFileParams
}

用法

yarn add vite-plugin-cos-upload -D
// vite.config.ts

import cosPlugin from 'vite-plugin-cos-upload'
import pkg from './package.json'

// config or .env
const cosConfig = {
    SecretId: '',
    SecretKey: '',
    Bucket: '',
    Region: '',
}

/** 项目文件夹地址 */
const basePath = pkg.name

/** cdn 地址 */
const cdnPrePath = ''

function uploadFileToCos(isUpload: boolean) {
    if (!isUpload) {
        return
    }

    return cosPlugin({
        ...cosConfig,
        prefix: basePath,
    })
}

export default defineConfig({
    plugins: [
        ...,
        base: process.env.NODE_ENV == 'production' ? cdnPrePath : `/`,
        uploadFileToCos(process.env.NODE_ENV == 'production')
        ...
    ]
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.