A Vite plugin that provides the equivalent of Webpack's __webpack_public_path__, allowing dynamic resolution of asset base path at runtime (e.g., loading from CDN). Version 1.1.0, actively maintained with steady updates. Ships TypeScript types and supports both modern and legacy builds (via @vitejs/plugin-legacy). Requires Vite >=2.8 as a peer dependency. Key differentiator: works for index.html and legacy bundles, not just JavaScript chunks.
npm install vite-plugin-public-pathNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Configures Vite to use a dynamic public path during production builds, with a placeholder base to be replaced at runtime via a global variable.
Order plugins: other plugins first, then publicPath(), then minifier plugins.
Use a distinctive placeholder like '/__VITE_BASE__/' and ensure it does not exist in your source.
N/A
Either set `html: true` or provide a string replacement for `html` option to replace the placeholder.
Ensure package is installed: npm i -D vite-plugin-public-path. Use ESM (import) syntax in vite.config.ts.
Use a more unique placeholder, e.g., '/__VITE_DYNAMIC_BASE__/', and verify it is not present in source code or asset contents.
Add a <script> tag in the HTML <head> that defines the variable before any other scripts (e.g., <script>window.__publicPath = '...';</script>).
Ensure you are using @vitejs/plugin-legacy and that the plugin is configured for legacy builds. Check GitHub issues for known limitations.