Skip to content

Commit

Permalink
fix: avoid excessive quote in css public urls
Browse files Browse the repository at this point in the history
close #1399
  • Loading branch information
yyx990803 committed Jan 7, 2021
1 parent 11c407a commit 1437129
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/playground/assets/css/css-url.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { FS_PREFIX } from '../constants'
import { PluginContext } from 'rollup'
import MagicString from 'magic-string'

export const assetUrlRE = /"__VITE_ASSET__(\w+)(?:__(.*)__)?"/g
export const assetUrlRE = /__VITE_ASSET__([a-z\d]+)(?:__(.*)__)?/g

// urls in JS must be quoted as strings, so when replacing them we need
// a different regex
const assetUrlQuotedRE = /"__VITE_ASSET__([a-z\d]+)(?:__(.*)__)?"/g

/**
* Also supports loading plain strings with import text from './foo.txt?raw'
Expand Down Expand Up @@ -51,7 +55,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
renderChunk(code) {
let match
let s
while ((match = assetUrlRE.exec(code))) {
while ((match = assetUrlQuotedRE.exec(code))) {
s = s || (s = new MagicString(code))
const [full, fileHandle, postfix = ''] = match
const outputFilepath =
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
if (cssUrlRE.test(css)) {
css = await rewriteCssUrls(css, async (url) => {
url = await urlToBuiltUrl(url, id, config, this)
return isDataUrl(url) ? url : JSON.stringify(url)
return url
})
}
}
Expand Down

0 comments on commit 1437129

Please sign in to comment.