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

refactor: remove redundant prepend/strip base #17887

Merged
merged 2 commits into from
Aug 16, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ export async function fileToUrl(
}
}

function fileToDevUrl(id: string, config: ResolvedConfig) {
export function fileToDevUrl(
id: string,
config: ResolvedConfig,
skipBase = false,
): string {
let rtn: string
if (checkPublicFile(id, config)) {
// in public dir during dev, keep the url as-is
Expand All @@ -281,6 +285,9 @@ function fileToDevUrl(id: string, config: ResolvedConfig) {
// (this is special handled by the serve static middleware
rtn = path.posix.join(FS_PREFIX, id)
}
if (skipBase) {
return rtn
}
const base = joinUrlSegments(config.server?.origin ?? '', config.decodedBase)
return joinUrlSegments(base, removeLeadingSlash(rtn))
}
Expand Down
8 changes: 2 additions & 6 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import {
removeDirectQuery,
removeUrlQuery,
requireResolveFromRootWithFallback,
stripBase,
stripBomTag,
urlRE,
} from '../utils'
Expand All @@ -75,6 +74,7 @@ import type { TransformPluginContext } from '../server/pluginContainer'
import { addToHTMLProxyTransformResult } from './html'
import {
assetUrlRE,
fileToDevUrl,
fileToUrl,
generatedAssets,
publicAssetUrlCache,
Expand Down Expand Up @@ -995,16 +995,12 @@ export function cssAnalysisPlugin(config: ResolvedConfig): Plugin {
// record deps in the module graph so edits to @import css can trigger
// main import to hot update
const depModules = new Set<string | ModuleNode>()
const devBase = config.base
for (const file of pluginImports) {
depModules.add(
isCSSRequest(file)
? moduleGraph.createFileOnlyEntry(file)
: await moduleGraph.ensureEntryFromUrl(
stripBase(
await fileToUrl(file, config, this),
(config.server?.origin ?? '') + devBase,
),
fileToDevUrl(file, config, /* skipBase */ true),
ssr,
),
)
Expand Down