Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html): make build-html plugin work with sharedPlugins #18214

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { toOutputFilePathInHtml } from '../build'
import { resolveEnvPrefix } from '../env'
import type { Logger } from '../logger'
import { cleanUrl } from '../../shared/utils'
import { usePerEnvironmentState } from '../environment'
import {
assetUrlRE,
getPublicAssetFilename,
Expand Down Expand Up @@ -320,7 +321,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
preHooks.push(htmlEnvHook(config))
postHooks.push(injectNonceAttributeTagHook(config))
postHooks.push(postImportMapHook())
const processedHtml = new Map<string, string>()
const processedHtml = usePerEnvironmentState(() => new Map<string, string>())

const isExcludedUrl = (url: string) =>
url[0] === '#' || isExternalUrl(url) || isDataUrl(url)
Expand Down Expand Up @@ -674,7 +675,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
}
}

processedHtml.set(id, s.toString())
processedHtml(this).set(id, s.toString())

// inject module preload polyfill only when configured and needed
const { modulePreload } = this.environment.config.build
Expand Down Expand Up @@ -778,7 +779,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
return tags
}

for (const [normalizedId, html] of processedHtml) {
for (const [normalizedId, html] of processedHtml(this)) {
const relativeUrlPath = normalizePath(
path.relative(config.root, normalizedId),
)
Expand Down