Skip to content

Commit 3b8f03d

Browse files
authoredAug 16, 2024··
refactor: remove redundant prepend/strip base (#17887)
1 parent fac3a8e commit 3b8f03d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
 

‎packages/vite/src/node/plugins/asset.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ export async function fileToUrl(
268268
}
269269
}
270270

271-
function fileToDevUrl(id: string, config: ResolvedConfig) {
271+
export function fileToDevUrl(
272+
id: string,
273+
config: ResolvedConfig,
274+
skipBase = false,
275+
): string {
272276
let rtn: string
273277
if (checkPublicFile(id, config)) {
274278
// in public dir during dev, keep the url as-is
@@ -281,6 +285,9 @@ function fileToDevUrl(id: string, config: ResolvedConfig) {
281285
// (this is special handled by the serve static middleware
282286
rtn = path.posix.join(FS_PREFIX, id)
283287
}
288+
if (skipBase) {
289+
return rtn
290+
}
284291
const base = joinUrlSegments(config.server?.origin ?? '', config.decodedBase)
285292
return joinUrlSegments(base, removeLeadingSlash(rtn))
286293
}

‎packages/vite/src/node/plugins/css.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import {
6565
removeDirectQuery,
6666
removeUrlQuery,
6767
requireResolveFromRootWithFallback,
68-
stripBase,
6968
stripBomTag,
7069
urlRE,
7170
} from '../utils'
@@ -75,6 +74,7 @@ import type { TransformPluginContext } from '../server/pluginContainer'
7574
import { addToHTMLProxyTransformResult } from './html'
7675
import {
7776
assetUrlRE,
77+
fileToDevUrl,
7878
fileToUrl,
7979
generatedAssets,
8080
publicAssetUrlCache,
@@ -996,16 +996,12 @@ export function cssAnalysisPlugin(config: ResolvedConfig): Plugin {
996996
// record deps in the module graph so edits to @import css can trigger
997997
// main import to hot update
998998
const depModules = new Set<string | ModuleNode>()
999-
const devBase = config.base
1000999
for (const file of pluginImports) {
10011000
depModules.add(
10021001
isCSSRequest(file)
10031002
? moduleGraph.createFileOnlyEntry(file)
10041003
: await moduleGraph.ensureEntryFromUrl(
1005-
stripBase(
1006-
await fileToUrl(file, config, this),
1007-
(config.server?.origin ?? '') + devBase,
1008-
),
1004+
fileToDevUrl(file, config, /* skipBase */ true),
10091005
ssr,
10101006
),
10111007
)

0 commit comments

Comments
 (0)
Please sign in to comment.