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 env replacement plugin position #12404

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_FOO=bar
VITE_FAVICON_URL=/sprite.svg
5 changes: 5 additions & 0 deletions playground/html/__tests__/html.spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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%" />