npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-oss-pro

v1.1.1

Published

一个可以将打包好的资源文件上传到阿里云OSS并且修改代码中资源文件CND地址的Vite插件

Downloads

18

Readme

vite-plugin-oss-pro

一个可以将打包好的资源文件上传到阿里云 OSS 并且修改代码中资源文件 CND 地址的 Vite 插件

传送门 webpack版

Install 安装

npm i vite-plugin-oss-pro -D

Options 配置参数

  • cdnHost: 必传。上传后要替换的资源文件 CDN 域名 URL
  • region: 必传。阿里云上传区域
  • accessKeyId: 必传。阿里云的授权 accessKeyId
  • accessKeySecret: 必传。阿里云的授权 accessKeySecret
  • bucket: 必传。上传到哪个 bucket
  • from: 必传。上传哪些文件,支持类似 gulp.src 的 glob 方法,如'./build/**', 为 glob 字符串。默认./dist/assets/**
  • dist: 上传到 oss 哪个目录下,默认为 oss 根目录。可作为路径前缀使用。
  • timeout: oss 超时设置,默认为 30 秒(30000)
  • overwrite: 是否覆盖 oss 同名文件。默认 true。
  • verbose: 是否显示上传日志,默认为 true。
  • deleteOrigin: 上传完成是否删除原文件,默认 false。
  • deleteEmptyDir: 如果某个目录下的文件都上传过了,是否删除此目录。deleteOrigin 为 true 时候生效。默认 false。
  • setOssPath: 自定义每个文件上传路径。接收参数为当前文件路径。不传,或者所传函数返回 false 则按默认方式上传。
  • test: 测试,仅查看文件和上传路径,但是不执行上传操作。默认 false。
  • quitWpOnError: 出错是否中断打包。默认 false。
  • version: 版本号。默认为''。
  • setVersion: 设置线上的版本号的方法。一般为 axios 请求方法,需同时配置 version。
  • fileSuffix: 需要上传的文件后缀,默认['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp', 'ico', 'bmp', 'webm', 'avi', 'mp4', 'mp3', 'flv', 'mov']
  • assetsDirectory: 要上传的资源文件目录,默认assets
  • outputDirectory: 项目打包后的目录,默认dist

注意: accessKeyId, accessKeySecret 很重要,注意保密!!!

使用示例

// vite.config.js
import { defineConfig } from "vite";
import ViteOSSPluginPro from "vite-plugin-oss-pro";

const prod = process.env.NODE_ENV === "production";

export default defineConfig({
  plugins: [
    // 打包时才加载插件
    prod &&
      ViteOSSPluginPro({
        cdnHost: "https://cdn.xxx.com",
        from: "./dist/assets/**", // 上传那个文件或文件夹
        dist: "/static", // 需要上传到oss上的给定文件目录
        region: "oss-xx-xx-1",
        accessKeyId: "xxxxxxxxxxxx",
        accessKeySecret: "xxxxxxxxxxxx",
        bucket: "xxxxxxxxx",
      }),
  ].filter(Boolean),
});