Skip to content

Commit

Permalink
fix: html env replacement plugin position (#12404)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Mar 15, 2023
1 parent fe1d61a commit 96f36a9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/html.ts
Expand Up @@ -286,7 +286,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
config.plugins,
)
preHooks.unshift(preImportMapHook(config))
normalHooks.unshift(htmlEnvHook(config))
preHooks.push(htmlEnvHook(config))
postHooks.push(postImportMapHook())
const processedHtml = new Map<string, string>()
const isExcludedUrl = (url: string) =>
Expand Down
1 change: 1 addition & 0 deletions playground/html/.env
@@ -1 +1,2 @@
VITE_FOO=bar
VITE_FAVICON_URL=/sprite.svg
5 changes: 5 additions & 0 deletions playground/html/__tests__/html.spec.ts
Expand Up @@ -273,6 +273,11 @@ describe('env', () => {
expect(await page.textContent('.env-bar')).toBeTruthy()
expect(await page.textContent('.env-prod')).toBe(isBuild + '')
expect(await page.textContent('.env-dev')).toBe(isServe + '')

const iconLink = await page.$('link[rel=icon]')
expect(await iconLink.getAttribute('href')).toBe(
`${isBuild ? './' : '/'}sprite.svg`,
)
})
})

Expand Down
1 change: 1 addition & 0 deletions playground/html/env.html
Expand Up @@ -3,3 +3,4 @@
<p class="env-%VITE_FOO%">class name should be env-bar</p>
<p class="env-prod">%PROD%</p>
<p class="env-dev">%DEV%</p>
<link rel="icon" href="%VITE_FAVICON_URL%" />

0 comments on commit 96f36a9

Please sign in to comment.