Skip to content

Commit

Permalink
fix(worker): dont throw on import.meta.url in ssr (#8846)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Jun 29, 2022
1 parent 1a498f7 commit ef749ed
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/vite/src/node/plugins/workerImportMetaUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
name: 'vite:worker-import-meta-url',

async transform(code, id, options) {
const query = parseRequest(id)
let s: MagicString | undefined
if (
!options?.ssr &&
(code.includes('new Worker') || code.includes('new SharedWorker')) &&
code.includes('new URL') &&
code.includes(`import.meta.url`)
) {
const query = parseRequest(id)
let s: MagicString | undefined
const cleanString = stripLiteral(code)
const workerImportMetaUrlRE =
/\bnew\s+(Worker|SharedWorker)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/g
Expand All @@ -96,13 +97,6 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
const urlEnd = urlStart + emptyUrl.length
const rawUrl = code.slice(urlStart, urlEnd)

if (options?.ssr) {
this.error(
`\`new URL(url, import.meta.url)\` is not supported in SSR.`,
urlIndex
)
}

// potential dynamic template string
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
this.error(
Expand Down

0 comments on commit ef749ed

Please sign in to comment.