Skip to content
Closed
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
42 changes: 21 additions & 21 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,27 +380,6 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {

url = normalizeResolvedIdToUrl(environment, url, resolved)

// make the URL browser-valid
if (environment.config.consumer === 'client') {
// mark non-js/css imports with `?import`
if (isExplicitImportRequired(url)) {
url = injectQuery(url, 'import')
} else if (
(isRelative || isSelfImport) &&
!DEP_VERSION_RE.test(url)
) {
// If the url isn't a request for a pre-bundled common chunk,
// for relative js/css imports, or self-module virtual imports
// (e.g. vue blocks), inherit importer's version query
// do not do this for unknown type imports, otherwise the appended
// query can break 3rd party plugin's extension checks.
const versionMatch = DEP_VERSION_RE.exec(importer)
if (versionMatch) {
url = injectQuery(url, versionMatch[1])
}
}
}

try {
// delay setting `isSelfAccepting` until the file is actually used (#7870)
// We use an internal function to avoid resolving the url again
Expand All @@ -425,6 +404,27 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
throw e
}

// make the URL browser-valid
if (environment.config.consumer === 'client') {
// mark non-js/css imports with `?import`
if (isExplicitImportRequired(url)) {
url = injectQuery(url, 'import')
} else if (
(isRelative || isSelfImport) &&
!DEP_VERSION_RE.test(url)
) {
// If the url isn't a request for a pre-bundled common chunk,
// for relative js/css imports, or self-module virtual imports
// (e.g. vue blocks), inherit importer's version query
// do not do this for unknown type imports, otherwise the appended
// query can break 3rd party plugin's extension checks.
const versionMatch = DEP_VERSION_RE.exec(importer)
if (versionMatch) {
url = injectQuery(url, versionMatch[1])
}
}
}

// prepend base
if (!ssr) url = joinUrlSegments(base, url)

Expand Down
7 changes: 3 additions & 4 deletions packages/vite/src/node/plugins/optimizedDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function optimizedDepsPlugin(): Plugin {
if (depsOptimizer?.isOptimizedDepFile(id)) {
const metadata = depsOptimizer.metadata
const file = cleanUrl(id)
const versionMatch = DEP_VERSION_RE.exec(file)
const versionMatch = DEP_VERSION_RE.exec(id)
const browserHash = versionMatch
? versionMatch[1].split('=')[1]
: undefined
Expand Down Expand Up @@ -77,9 +77,8 @@ export function optimizedDepsPlugin(): Plugin {
try {
return await fsp.readFile(file, 'utf-8')
} catch {
const newMetadata = depsOptimizer.metadata
if (optimizedDepInfoFromFile(newMetadata, file)) {
// Outdated non-entry points (CHUNK), loaded after a rerun
if (browserHash) {
// Outdated optimized files loaded after a rerun
throwOutdatedRequest(id)
}
throwFileNotFoundInOptimizedDep(id)
Expand Down
Loading