Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/assetImportMetaUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
id: {
exclude: [exactRegex(preloadHelperId), exactRegex(CLIENT_ENTRY)],
},
code: /new\s+URL.+import\.meta\.url/,
code: /new\s+URL.+import\.meta\.url/s,
},
async handler(code, id) {
let s: MagicString | undefined
Expand Down
11 changes: 11 additions & 0 deletions playground/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ <h2>new URL(`${dynamic}`, import.meta.url)</h2>
<code class="dynamic-import-meta-url-all"></code>
</p>

<h2>Multiline new URL(..., import.meta.url)</h2>
<p>Multiline URL 1: <code class="multiline-url-1"></code></p>
<p>Multiline URL 2: <code class="multiline-url-2"></code></p>
<p>Multiline URL 3: <code class="multiline-url-3"></code></p>
Comment thread
sapphi-red marked this conversation as resolved.
Outdated

<h2>simple script tag import-expression</h2>
<code class="import-expression"></code>
<code class="obj-import-express"></code>
Expand Down Expand Up @@ -709,6 +714,12 @@ <h3>assets in template</h3>
text(`.dynamic-import-meta-url-all`, metaUrl)
}

// Test multiline new URL(..., import.meta.url) expressions
// Import from separate file to test multiline expressions are correctly processed
Comment thread
sapphi-red marked this conversation as resolved.
Outdated
import('./multiline-import-meta-url.js').then((module) => {
text('.multiline-url-1', module.multilineUrl)
Comment thread
sapphi-red marked this conversation as resolved.
Outdated
})

function text(el, text) {
document.querySelector(el).textContent = text
}
Expand Down
11 changes: 11 additions & 0 deletions playground/assets/multiline-import-meta-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Test for multiline new URL(..., import.meta.url) expressions
// This is a separate file to ensure the regex filter in assetImportMetaUrlPlugin
// correctly detects and processes multiline expressions that span multiple lines.
// The bug was that the filter regex didn't include the 's' flag, so multiline
// expressions were not being processed by the plugin.
Comment thread
sapphi-red marked this conversation as resolved.
Outdated

export const multilineUrl = new URL(
'./nested/fragment.svg',

import.meta.url,
)