Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ikasoba/vite-plugin-cdn

cdn plugin for vite
https://github.com/ikasoba/vite-plugin-cdn

Last synced: 2 months ago
JSON representation

cdn plugin for vite

Awesome Lists containing this project

README

        


vite-plugin-cdn📦

Plugin to use javascript package cdn in vite.

```ts
import { defineConfig } from "vite";
import cdn from "@ikasoba000/vite-plugin-cdn";

export default defineConfig({
plugins: [
cdn()
],
});
```

# about

vite-plugin-cdn refers to esm.sh by default, but it can also refer to cdn such as skypack.

```ts
export default defineConfig({
plugins: [
cdn({
// :name, :version, and :path are variable items.
format: "https://cdn.skypack.dev/:name@:version/:path"
})
],
});
```

The pattern can also specify a function.

```ts
export default defineConfig({
plugins: [
cdn({
format(name: string, version: string, path?: string) {
return name == "react"
? `https://esm.sh/preact@${version}/${path ?? ""}`
: `https://cdn.skypack.dev/${name}@${version}/${path ?? ""}`;
}
})
],
});
```

You can explicitly select or exclude packages to be loaded from cdn.

```ts
export default defineConfig({
plugins: [
cdn({
// By default, all packages are loaded from cdn.
includes: [ , ... ]
})
],
});

// or

export default defineConfig({
plugins: [
cdn({
// Packages specified here are not loaded from cdn,
// but are bundled by vite in many cases.
excludes: [ , ... ]
})
],
});
```