Skip to content

Commit

Permalink
fix: mixed match result of importMetaUrl (#4482)
Browse files Browse the repository at this point in the history
  • Loading branch information
dejour committed Aug 3, 2021
1 parent 056b17e commit 86f673a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/vite/src/node/plugins/assetImportMetaUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import path from 'path'
import { fileToUrl } from './asset'
import { ResolvedConfig } from '../config'

const importMetaUrlRE =
/\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\)/g

/**
* Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL
*
Expand All @@ -22,6 +19,8 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
name: 'asset-import-meta-url',
async transform(code, id, ssr) {
if (code.includes('new URL') && code.includes(`import.meta.url`)) {
const importMetaUrlRE =
/\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\)/g
let s: MagicString | null = null
let match: RegExpExecArray | null
while ((match = importMetaUrlRE.exec(code))) {
Expand Down

0 comments on commit 86f673a

Please sign in to comment.