Skip to content

Commit

Permalink
fix(html): rewrite assets url in <noscript> (#11764)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Feb 18, 2023
1 parent 70729c0 commit 1dba285
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export async function traverseHtml(
// lazy load compiler
const { parse } = await import('parse5')
const ast = parse(html, {
scriptingEnabled: false, // parse inside <noscript>
sourceCodeLocationInfo: true,
onParseError: (e: ParserError) => {
handleParseError(e, html, filePath)
Expand Down
7 changes: 7 additions & 0 deletions playground/assets/__tests__/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,10 @@ test.skip('url() contains file in publicDir, as inline style', async () => {
// (I built the playground to verify)
expect(await getBg('.inline-style-public')).toContain(iconMatch)
})

test.runIf(isBuild)('assets inside <noscript> is rewrote', async () => {
const indexHtml = readFile('./dist/foo/index.html')
expect(indexHtml).toMatch(
/<img class="noscript" src="\/foo\/assets\/asset-\w+\.png" \/>/,
)
})
6 changes: 6 additions & 0 deletions playground/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ <h3>style in svg</h3>
/>
</g>
</svg>

<h3>assets in noscript</h3>
<noscript>
<img class="noscript" src="./nested/asset.png" />
</noscript>

<link rel="stylesheet" href="asset/style.css" />
<div class="relative-css">link style</div>
<div class="relative-js"></div>
Expand Down

0 comments on commit 1dba285

Please sign in to comment.