Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
const isDynamicImport = dynamicIndex > -1

// strip import attributes as we can process them ourselves
if (!isDynamicImport && attributeIndex > -1) {
if (attributeIndex > -1) {
str().remove(end + 1, expEnd)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ test('from source code', async () => {
test('from dependency', async () => {
expect(await page.textContent('.dep'), 'world')
})

test('dynamic import with attributes', async () => {
expect(await page.textContent('.dynamic'), 'bar')
})
6 changes: 6 additions & 0 deletions playground/import-assertion/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ <h2>From source code</h2>
<h2>From dependency</h2>
<p class="dep"></p>

<p class="dynamic"></p>

<script type="module">
import * as data from './data.json' assert { type: 'json' }
text('.src', data.foo)

import * as depData from '@vitejs/test-import-assertion-dep'
text('.dep', depData.hello)

import('./data.json', { with: { type: 'json' } }).then((m) =>
text('.dynamic', m.foo),
)

function text(el, text) {
document.querySelector(el).textContent = text
}
Expand Down
Loading