Skip to content

Resolve all resource files dynamic publicpath, like Webpack's __webpack_public_path__

License

Notifications You must be signed in to change notification settings

chenxch/vite-plugin-dynamic-base

Repository files navigation

vite-plugin-dynamic-base

NPM version

English | 简体中文

  • 🦾 Resolve all resource files dynamic publicPath, like Webpack's __webpack_public_path__.

Installation

npm i vite-plugin-dynamic-base -D

Changelog

0.4.1

2022-05-09

Bug fixes

  • Legacy is invalid in browsers such as IE11.

Changelogs

Build Mode

  • es
  • system

Compatible plugins

Usage

// vite.config.ts
import { dynamicBase } from 'vite-plugin-dynamic-base'

export default defineConfig({
  // base: "/",
  base: process.env.NODE_ENV === "production" ? "/__dynamic_base__/" : "/",
  plugins: [
    dynamicBase({ /* options */ }),
  ],
})

Configuration

The following show the default values of the configuration

dynamicBase({
  // dynamic public path var string, default window.__dynamic_base__
  publicPath: 'window.__dynamic_base__',
  // dynamic load resources on index.html, default false. maybe change default true
  transformIndexHtml:  false
})

Plan

  1. Exploring the feasibility of using SWC to transform the AST for processing