Skip to content

Commit

Permalink
Merge pull request #98 from cyanzhong/main
Browse files Browse the repository at this point in the history
Fix __VITE_PRELOAD__ regression in vite 5.3
  • Loading branch information
richardtallent committed Jun 20, 2024
2 parents 5fcf63b + 7a1af06 commit b74266e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const defaultConfig = { useRecommendedBuildConfig: true, removeViteModuleLoader:
export function replaceScript(html: string, scriptFilename: string, scriptCode: string, removeViteModuleLoader = false): string {
const reScript = new RegExp(`<script([^>]*?) src="[./]*${scriptFilename}"([^>]*)></script>`)
// we can't use String.prototype.replaceAll since it isn't supported in Node.JS 14
const preloadMarker = /"__VITE_PRELOAD__"/g
const preloadMarker = /"?__VITE_PRELOAD__"?/g
const newCode = scriptCode.replace(preloadMarker, "void 0")
const inlined = html.replace(reScript, (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>${newCode}</script>`)
return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined
Expand Down

0 comments on commit b74266e

Please sign in to comment.