
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
vite-plugin-fast-cdn-import
Advanced tools
从多个 CDN 中找出最快的源并加载资源
Find the fastest source from multiple CDNs and load resources
目前本插件不支持 js 包的加载,仅支持 css 包的加载!!
https://github.com/CaoMeiYouRen/vite-plugin-fast-cdn-import#readme
https://github.com/CaoMeiYouRen/vite-plugin-fast-cdn-import#readme
npm install vite-plugin-fast-cdn-import
// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tsconfigPaths from 'vite-tsconfig-paths'
import { vitePluginFastCdnImport } from 'vite-plugin-fast-cdn-import'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
tsconfigPaths(),
vitePluginFastCdnImport({ // 添加依赖即可
cdnUrls: [ // 指定 CDN 源
'https://npm.elemecdn.com/:name@:version/:path',
'https://cdn.jsdelivr.net/npm/:name@:version/:path',
'https://unpkg.com/:name@:version/:path',
],
modules: [ // 目前仅支持 css 的加载
{
name: 'normalize.css',
path: 'normalize.css',
},
{
name: 'element-plus',
path: 'dist/index.css',
},
],
}),
],
server: {
port: 4000,
open: true,
proxy: {},
},
})
export interface Module {
/**
* 包的名称
*/
name: string
/**
* 以手动填写为准,默认会去 node_modules 下获取已安装的版本号
*/
version?: string
/**
* 以外部包形式载入时的全局变量名称,载入的资源是 js 时使用
*/
var?: string
/**
* 需要加载的资源路径,相对于包的地址
*/
path: string
/**
* 是否为纯 css
*/
cssOnly?: boolean
/**
* 是否为 es module
*/
esModule?: boolean
}
export interface Options {
/**
* 要加载的包
*/
modules: Module[]
/**
* CDN 的地址,格式:https://unpkg.com/:name@:version/:path
*/
cdnUrls?: string[]
/**
* 禁用本插件
*/
disabled?: boolean
/**
* 全量竞速,即对每一个包都进行一次竞速
*/
allRace?: boolean
/**
* 手动指定缓存key,改变cacheKey会使之前的缓存失效
*/
cacheKey?: string
}
在指定的多个 CDN 源中,会使用 fetch对第一个包的地址进行一次 HEAD 请求,得出最快的源,剩余的包不再竞速,直接采用该结果。
第一次的竞速结果会缓存在 localStorage 中,直到包的数量或版本号发生了改变,此时缓存失效,重复上述流程。
allRace为 true启用全量竞速,会对每一个包都单独竞速。虽然可以解决包不存在的问题,但也多了竞速的耗时,请开发者自行权衡。fetch,所以在不支持 fetch 的浏览器下无法竞速,也就无法加载包。Promise.race、Promise.any,所以在不支持 Promise.race、Promise.any 的浏览器中需要 polyfill 才能使用cacheKey 来解决。原因是 css 的加载对顺序没有要求,故早点晚点加载没有太大影响,但 js 的加载对顺序有要求,依赖包需要先加载,故 js 部分不采用竞速加载的模式。
npm run dev
npm run build
npm run lint
npm run commit
👤 CaoMeiYouRen
欢迎 贡献、提问或提出新功能!
如有问题请查看 issues page.
贡献或提出新功能可以查看contributing guide.
如果觉得这个项目有用的话请给一颗⭐️,非常感谢
Copyright © 2022 CaoMeiYouRen.
This project is MIT licensed.
This README was generated with ❤️ by cmyr-template-cli
FAQs
从多个 CDN 中找出最快的源并加载资源
The npm package vite-plugin-fast-cdn-import receives a total of 0 weekly downloads. As such, vite-plugin-fast-cdn-import popularity was classified as not popular.
We found that vite-plugin-fast-cdn-import demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.