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-cos-cdnizer

v1.0.0

Published

一个替换本地静态资源引用为已上传至 CDN 地址的 vite 插件。

Downloads

4

Readme

vite-plugin-cos-cdnizer

在日常开发中,经常需要将静态资源上传到云服务的对象存储中。传统方式需要开发者手动登录云服务器控制台进行上传,步骤繁琐。

使用本插件后,只需要将静态资源放置在项目本地,插件将自动将命中的资源上传到对象存储中。同时,插件会自动将代码中的 import xxx from 'xxx.png' 替换为 CDN 地址,简化开发流程。

安装

npm install vite-plugin-cos-cdnizer -D

基本使用

import { defineConfig } from 'vite';
import cdnizer from 'vite-plugin-cos-cdnizer';

export default defineConfig({
	plugins: [
		cdnizer({
			secretId: 'yourSecretId',
			secretKey: 'yourSecretKey',
			bucket: 'yourBucket',
			region: 'yourRegion',
			domain: 'yourCustomCDNDomain'
		})
	]
});

效果展示

插件会自动将本地引入的静态资源上传至 CDN,并替换原有代码中的引用地址为 CDN 地址。

使用前

image-20240228下午63239358

使用后

image-20240228下午63154556

success

插件会自动创建 .cache.json 文件进行记录,以减少无用的重复上传。

cache

参数配置

| 参数名 | 类型 | 描述 | 默认值 | 必填 | | ----------------- | ------------------------------------- | --------------------------------- | ------------------------------------------- | ---- | | secretId | string | 身份密钥 ID | - | 是 | | secretKey | string | 身份密钥 Key | - | 是 | | bucket | string | 存储桶的名称 | - | 是 | | region | string | 存储桶所在地域 | - | 是 | | domain | string | 自定义 CDN 域名 | ${bucket}.cos.${region}.myqcloud.com | 否 | | uploadPath | string | 自定义上传路径 | ${projectName}/${fileName} | 否 | | include | string[] 或 (path: string) => boolean | 自定义命中文件规则 | ['.png', '.jpg', '.jpeg', '.svg', '.gif'] | 否 | | enableMD5FileName | boolean | 是否对上传的文件名称进行 MD5 编码 | true | 否 | | enableCache | boolean | 是否缓存已上传文件 | true | 否 |