/vite-plugin-cdn

replace module with CDN. work with vite.

Primary LanguageTypeScriptMIT LicenseMIT

vite-plugin-cdn

Coverage Status

Quick Start

Install

$ yarn add vite-plugin-cdn2 -D

# or

$ npm install vite-plugin-cdn2 -D

Usage

// vite.config.ts

import { defineConfig } from 'vite'

import { cdn } from 'vite-plugin-cdn2'

export default defineConfig({
  plugins: [
    //  ... your plugin
    cdn({ modules: ['vue'] })
  ]
})

Options

include

Type:

type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null

Default: /\.(mjs|js|ts|vue|jsx|tsx)(\?.*|)$/

Include all assets matching any of these conditions.

exclude

Type:

type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null

Default: undefined

Exclude all assets matching any of these conditions.

modules

Type:

interface TrackModule {
  name: string
  global?: string
  spare?: Array<string> | string 
  relativeModule?: string
}

type ResolverFunction = (p: string, extra: IIFEModuleInfo)=> string

interface IModule extends TrackModule{
  resolve: string | ResolverFunction
}

type Modules = Array<IModule | string>

Default: []

Modules to be processed. Details see Modules.

url

Type: string

Default: https://cdn.jsdelivr.net/npm/

CDN url. Details see URL.

transform

Type:

interface InjectVisitor {
  script?: (node: ScriptNode)=> void
  link?: (node: LinkNode)=> void
}

type Trasnform = ()=> InjectVisitor

Default: undefined

Transform is a overwrite.

logLevel

Type: slient | warn

Default: warn

Adjust console output verbosity.

resolve

Type: ResolverFunction

Default: undefined

A global url parser.

apply

Type: build | serve

Default: build

Same as vite command

Acknowledgements

Thanks to JetBrains for allocating free open-source licences for IDEs such as WebStorm.

JetBrains Black Box Logo logo.

Document

LICENSE

MIT

Author

Kanno