Skip to content

Commit

Permalink
chore: revert "fix: don't add ?import for @vite-ignoreed import (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 3, 2023
1 parent 6725666 commit 6516607
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
15 changes: 7 additions & 8 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,12 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
server.warmupRequest(url, { ssr })
}
} else if (!importer.startsWith(withTrailingSlash(clientDir))) {
// check @vite-ignore which suppresses dynamic import warning
const hasViteIgnore = hasViteIgnoreRE.test(
// complete expression inside parens
source.slice(dynamicIndex + 1, end),
)
if (!isInNodeModules(importer)) {
// check @vite-ignore which suppresses dynamic import warning
const hasViteIgnore = hasViteIgnoreRE.test(
// complete expression inside parens
source.slice(dynamicIndex + 1, end),
)
if (!hasViteIgnore) {
this.warn(
`\n` +
Expand All @@ -652,9 +652,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
if (!ssr) {
const url = rawUrl.replace(cleanUpRawUrlRE, '').trim()
if (
!hasViteIgnore &&
(!urlIsStringRE.test(url) ||
isExplicitImportRequired(url.slice(1, -1)))
!urlIsStringRE.test(url) ||
isExplicitImportRequired(url.slice(1, -1))
) {
needQueryInjectHelper = true
str().overwrite(
Expand Down
22 changes: 6 additions & 16 deletions playground/dynamic-import/__tests__/dynamic-import.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { expect, test } from 'vitest'
import {
getColor,
isBuild,
isServe,
page,
serverLogs,
untilUpdated,
} from '~utils'
import { getColor, isBuild, page, serverLogs, untilUpdated } from '~utils'

test('should load literal dynamic import', async () => {
await page.click('.baz')
Expand Down Expand Up @@ -37,14 +30,11 @@ test('should have same reference on static and dynamic js import, .mxd', async (
await untilUpdated(() => page.textContent('.view'), 'true', true)
})

// in this case, it is not possible to detect the correct module in build
test.runIf(isServe)(
'should have same reference on static and dynamic js import, .mxd2',
async () => {
await page.click('.mxd2')
await untilUpdated(() => page.textContent('.view'), 'true')
},
)
// in this case, it is not possible to detect the correct module
test('should have same reference on static and dynamic js import, .mxd2', async () => {
await page.click('.mxd2')
await untilUpdated(() => page.textContent('.view'), 'false', true)
})

test('should have same reference on static and dynamic js import, .mxdjson', async () => {
await page.click('.mxdjson')
Expand Down
2 changes: 2 additions & 0 deletions playground/dynamic-import/nested/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ document.querySelector('.mxd').addEventListener('click', async () => {

document.querySelector('.mxd2').addEventListener('click', async () => {
const test = { jss: '../files/mxd.js' }
const ttest = test
const view = 'mxd'
const { default: mxdDynamic } = await import(/*@vite-ignore*/ test.jss)
text('.view', mxdStatic === mxdDynamic)
})
Expand Down

0 comments on commit 6516607

Please sign in to comment.