Skip to content

Commit

Permalink
fix(build): link href used data url (vitejs#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Jul 16, 2020
1 parent b16548f commit 8ae073e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/node/build/buildPluginHtml.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin, RollupOutput, OutputChunk } from 'rollup'
import path from 'path'
import fs from 'fs-extra'
import { isExternalUrl, cleanUrl } from '../utils/pathUtils'
import { isExternalUrl, cleanUrl, isDataUrl } from '../utils/pathUtils'
import { resolveAsset, registerAssets } from './buildPluginAsset'
import {
parse as Parse,
Expand Down Expand Up @@ -189,7 +189,8 @@ const compileHtml = async (
p.type === NodeTypes.ATTRIBUTE &&
p.value &&
assetAttrs.includes(p.name) &&
!isExternalUrl(p.value.content)
!isExternalUrl(p.value.content) &&
!isDataUrl(p.value.content)
) {
assetUrls.push(p)
}
Expand Down
3 changes: 3 additions & 0 deletions src/node/utils/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const parseWithQuery = (
const externalRE = /^(https?:)?\/\//
export const isExternalUrl = (url: string) => externalRE.test(url)

const dataUrlRE = /^\s*data:/i
export const isDataUrl = (url: string) => dataUrlRE.test(url)

const imageRE = /\.(png|jpe?g|gif|svg|ico|webp)(\?.*)?$/
const mediaRE = /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/
const fontsRE = /\.(woff2?|eot|ttf|otf)(\?.*)?$/i
Expand Down

0 comments on commit 8ae073e

Please sign in to comment.