Skip to content

Commit

Permalink
fix: Same pattern is used multiple times
Browse files Browse the repository at this point in the history
Additionally, remove hmr
  • Loading branch information
rpetersen27 committed Apr 13, 2021
1 parent 0760397 commit 689ee68
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ const clientDir = normalizePath(CLIENT_DIR)
const skipRE = /\.(map|json)$/
const canSkip = (id: string) => skipRE.test(id) || isDirectCSSRequest(id)

function isExplicitImportRequired(url: string) {
return !isJSRequest(cleanUrl(url)) && !isCSSRequest(url)
}
function markExplicitImport(url: string) {
if (!isJSRequest(cleanUrl(url)) && !isCSSRequest(url)) {
if (isExplicitImportRequired(url)) {
return injectQuery(url, 'import')
}
return url
Expand Down Expand Up @@ -407,22 +410,12 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
`/* @vite-ignore */ comment inside the import() call to suppress this warning.\n`
)
}
needQueryInjectHelper = true
if (
!/^('.*'|".*"|`.*`)$/.test(url) ||
(!isJSRequest(cleanUrl(url.slice(1, -1))) &&
!isCSSRequest(url.slice(1, -1)))
/^('.*'|".*"|`.*`)$/.test(url) &&
isExplicitImportRequired(url.slice(1, -1))
) {
needQueryInjectHelper = true
str().overwrite(start, end, `__vite__injectQuery(${url}, 'import')`)
} else {
const depModule = await moduleGraph.ensureEntryFromUrl(url)
if (depModule.lastHMRTimestamp > 0) {
str().overwrite(
start,
end,
`__vite__injectQuery(${url}, 't=${depModule.lastHMRTimestamp}')`
)
}
}
}
}
Expand Down

0 comments on commit 689ee68

Please sign in to comment.