Skip to content

Commit 96f36a9

Browse files
authoredMar 15, 2023
fix: html env replacement plugin position (#12404)
1 parent fe1d61a commit 96f36a9

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed
 

‎packages/vite/src/node/plugins/html.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
286286
config.plugins,
287287
)
288288
preHooks.unshift(preImportMapHook(config))
289-
normalHooks.unshift(htmlEnvHook(config))
289+
preHooks.push(htmlEnvHook(config))
290290
postHooks.push(postImportMapHook())
291291
const processedHtml = new Map<string, string>()
292292
const isExcludedUrl = (url: string) =>

‎playground/html/.env

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
VITE_FOO=bar
2+
VITE_FAVICON_URL=/sprite.svg

‎playground/html/__tests__/html.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ describe('env', () => {
273273
expect(await page.textContent('.env-bar')).toBeTruthy()
274274
expect(await page.textContent('.env-prod')).toBe(isBuild + '')
275275
expect(await page.textContent('.env-dev')).toBe(isServe + '')
276+
277+
const iconLink = await page.$('link[rel=icon]')
278+
expect(await iconLink.getAttribute('href')).toBe(
279+
`${isBuild ? './' : '/'}sprite.svg`,
280+
)
276281
})
277282
})
278283

‎playground/html/env.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
<p class="env-%VITE_FOO%">class name should be env-bar</p>
44
<p class="env-prod">%PROD%</p>
55
<p class="env-dev">%DEV%</p>
6+
<link rel="icon" href="%VITE_FAVICON_URL%" />

0 commit comments

Comments
 (0)
Please sign in to comment.