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: sourcemap path mangled by browser #1326

Merged
merged 1 commit into from
Jan 3, 2021
Merged
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
11 changes: 10 additions & 1 deletion packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { send } from '../send'
import { transformRequest } from '../transformRequest'
import { isHTMLProxy } from '../../plugins/html'
import chalk from 'chalk'
import { DEP_CACHE_DIR, DEP_VERSION_RE, VALID_ID_PREFIX } from '../../constants'
import {
DEP_CACHE_DIR,
DEP_VERSION_RE,
FS_PREFIX,
VALID_ID_PREFIX
} from '../../constants'

const debugCache = createDebugger('vite:cache')
const isDebug = !!process.env.DEBUG
Expand Down Expand Up @@ -46,6 +51,10 @@ export function transformMiddleware(
const isSourceMap = withoutQuery.endsWith('.map')
// since we generate source map references, handle those requests here
if (isSourceMap) {
// #1323 - browser may remove // when fetching source maps
if (url.startsWith(FS_PREFIX)) {
url = FS_PREFIX + url.split(FS_PREFIX)[1].replace(/^\/?/, '/')
}
const originalUrl = url.replace(/\.map($|\?)/, '$1')
const map = (await moduleGraph.getModuleByUrl(originalUrl))
?.transformResult?.map
Expand Down