Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic import warning with @vite-ignore #7533

Merged
merged 1 commit into from Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -8,6 +8,10 @@ test('should load literal dynamic import', async () => {
test('should load full dynamic import from public', async () => {
await page.click('.qux')
await untilUpdated(() => page.textContent('.view'), 'Qux view', true)
// No warning should be logged as we are using @vite-ignore
expect(
serverLogs.some((log) => log.includes('cannot be analyzed by vite'))
).toBe(false)
})

test('should load data URL of `blob:`', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/dynamic-import/nested/index.js
Expand Up @@ -35,7 +35,7 @@ document.querySelector('.mxd2').addEventListener('click', async () => {
const test = { jss: '../mxd.js' }
const ttest = test
const view = 'mxd'
const { default: mxdDynamic } = await import(test.jss)
const { default: mxdDynamic } = await import(/*@vite-ignore*/ test.jss)
text('.view', mxdStatic === mxdDynamic)
})

Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Expand Up @@ -518,7 +518,10 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
}
} else if (!importer.startsWith(clientDir) && !ssr) {
// check @vite-ignore which suppresses dynamic import warning
const hasViteIgnore = /\/\*\s*@vite-ignore\s*\*\//.test(rawUrl)
const hasViteIgnore = /\/\*\s*@vite-ignore\s*\*\//.test(
// complete expression inside parens
source.slice(dynamicIndex + 1, end)
)

const url = rawUrl
.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '')
Expand Down