All Projects → jy0529 → vite-plugin-dynamic-publicpath

jy0529 / vite-plugin-dynamic-publicpath

Licence: MIT License
Use dynamic import handler to change runtime public base path, like webpack's __webpack_public_path__.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to vite-plugin-dynamic-publicpath

vite-plugin-psvg
PSVG for Vite
Stars: ✭ 36 (+16.13%)
Mutual labels:  vite-plugin
unocss
The instant on-demand atomic CSS engine.
Stars: ✭ 7,866 (+25274.19%)
Mutual labels:  vite-plugin
vite-plugin-image-presets
🖼 Image Presets for Vite.js apps
Stars: ✭ 164 (+429.03%)
Mutual labels:  vite-plugin
vite-plugin-rescript
Integrate ReScript with Vite seamlessly
Stars: ✭ 56 (+80.65%)
Mutual labels:  vite-plugin
vite-plugins
🌱 为社区尽一份绵薄之力
Stars: ✭ 63 (+103.23%)
Mutual labels:  vite-plugin
vite-plugin-webfont-dl
⚡ Webfont Download Vite Plugin - Make your Vite site load faster
Stars: ✭ 69 (+122.58%)
Mutual labels:  vite-plugin
vite-plugin-env-compatible
Environment Variables Compatible for vite(with vue-cli, create-react-app and so on)
Stars: ✭ 35 (+12.9%)
Mutual labels:  vite-plugin
vite-plugin-inspect
Inspect the intermediate state of Vite plugins
Stars: ✭ 491 (+1483.87%)
Mutual labels:  vite-plugin
vite-plugin-ssr
Like Next.js / Nuxt but as do-one-thing-do-it-well Vite plugin.
Stars: ✭ 1,703 (+5393.55%)
Mutual labels:  vite-plugin
vite-plugin-environment
Easily expose environment variables in Vite.js
Stars: ✭ 57 (+83.87%)
Mutual labels:  vite-plugin
vite-plugin-restart
Custom files/globs to restart Vite server
Stars: ✭ 92 (+196.77%)
Mutual labels:  vite-plugin
vite-plugin-radar
All in one analytics loader for vite
Stars: ✭ 64 (+106.45%)
Mutual labels:  vite-plugin
vite-plugin-sleep
a vite plugin you never need. slow devServer and slow HMR.
Stars: ✭ 77 (+148.39%)
Mutual labels:  vite-plugin
vite-plugin-theme-preprocessor
css theme preprocessor plugin for vite
Stars: ✭ 144 (+364.52%)
Mutual labels:  vite-plugin
postcss-variable-compress
Minifies css variable names
Stars: ✭ 18 (-41.94%)
Mutual labels:  vite-plugin
vite-plugin-html-template
html template for vite, like html-webpack-plugin for webpack.
Stars: ✭ 97 (+212.9%)
Mutual labels:  vite-plugin
vite-plugin-banner
A banner plugin for Vite. It can adds a banner to the top of each generated chunk.
Stars: ✭ 39 (+25.81%)
Mutual labels:  vite-plugin
vite-plugin-checker
💬 Vite plugin that provide checks of TypeScript, ESLint, vue-tsc, and more.
Stars: ✭ 338 (+990.32%)
Mutual labels:  vite-plugin
vite-plugin-compress
Compress your bundle + assets from Vite
Stars: ✭ 103 (+232.26%)
Mutual labels:  vite-plugin
adorable-css
Rapid On-Demand Atomic CSS Framework
Stars: ✭ 131 (+322.58%)
Mutual labels:  vite-plugin

vite-plugin-dynamic-publicpath

Why

Use dynamic import handler to change runtime public base path, like webpack's __webpack_public_path__.

Usage

  • run yarn add vite-plugin-dynamic-publicpath --dev
  • add the plugin into vite.config.ts
// vite.config.ts

import { useDynamicPublicPath } from 'vite-plugin-dynamic-publicpath'
export default defineConfig({
  plugins: [
    useDynamicPublicPath(/** option */),
  ]
})

e.g. basic demo

// main.ts

// Your dynamic cdn
const dynamicCdn = oneOf(['cdn.xxx.com', 'cdn1.xxx.com']);
window.__dynamicImportHandler__ = function(importer) {
    return dynamicCdn + importer;
}
window.__dynamicImportPreload__ = function(preloads) {
    return preloads.map(preload => dynamicCdn + preload);
}

For legacy browser

e.g. legacy browser demo

// vite.config.ts

import legacy from '@vitejs/plugin-legacy'
import { useDynamicPublicPath } from 'vite-plugin-dynamic-publicpath'
export default defineConfig({
  plugins: [
    /**
     * @see https://github.com/vitejs/vite/tree/main/packages/plugin-legacy
     * /
    legacy({
      targets: ['defaults', 'not ie <= 8'] 
    }),
    /** Attention! The legacy plugin must before loaded than dynamic-publicpath plugin */
    useDynamicPublicPath({
      dynamicImportHandler: 'window.__dynamic_handler__',
      dynamicImportPreload: 'window.__dynamic_preload__'
    }),
  ]
})

Options

dynamicImportHandler

Type: string
Default: window.__dynamicImportHandler__

Register dynamic import handler

dynamicImportPreload

Type: string
Default: window.__dynamicImportPreload__

Register dynamic import preload handler

assetsBase

Type: string
Default: assets

Custom the assets directory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].