Détail du package

vite-plugin-dynamic-base

chenxch19.9kMIT1.2.0

Resolve all resource files dynamic publicPath, like Webpack's webpack_public_path

vite, vite plugin, publicpath, dynamic publicpath

readme

vite-plugin-dynamic-base

Version Languages License Star Download

English | 简体中文

  • 🦾 解析所有资源文件动态路径(多cdn切换), 类似 Webpack 的 __webpack_public_path__.

安装

npm i vite-plugin-dynamic-base -D

变更日志

变更日志

编译模式

  • [x] es
  • [x] system

兼容插件

使用

// 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 */ }),
  ],
})

配置

以下显示配置的默认值

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
  // provide conversion configuration parameters. by 1.1.0
  // transformIndexHtmlConfig: { insertBodyAfter: false }
})

changelog

Changelog

1.2.0

2025-06-05

Feat

  • transform HTML to support custom publicPath.

1.1.2

2025-06-04

Fix

  • update asset tag selector to include all relevant tags in transformHtml function. Change from head to global.

1.1.0

2024-05-15

Chore

  • support defer load script.

1.0.3

2024-04-29

Chore

  • add peerDependencies.

1.0.2

2024-02-02

Fix

  • Fix failing transformations due to wrong string / template order.

1.0.1

2024-02-02

Feat

  • Add support for replacement in template literals. (#28 by @joarfish)

1.0.0

2023-06-07

Feat

0.4.9

2023-04-11

Fix

  • fix html template src parse (#21)

0.4.8

2023-01-15

Fix

0.4.5

2022-09-07

Fix

  • support aysnc load components.(#14)

    0.4.4

2022-06-24

Feat

  • support legacy modernPolyfills.(#9)

0.4.3

2022-06-21

Bug fixes

  • template strings does not work.(#8)

0.4.1

2022-05-09

Bug fixes

  • Legacy is invalid in browsers such as IE11.

0.4.0

2022-05-01

Features

  • compatible vite-plugin-pwa
  • base mark

Bug fixes

  • Multi-level cdn reference resource path fix

Refactors

  • Replace the matching scheme and use the base attribute as a marker bit
  • Code structure adjustment, introduction of asynchronous processing

0.3.0

2022-04-23

Features

  • setup simple unit tests with vitest. (#5 by @zhoujinfu)

Bug fixes

  • import.env.LEGACY cause undefined errors with vite config define. (#5 by @zhoujinfu)