Skip to content

Commit

Permalink
fix: sourcemap path mangled by browser (#1326)
Browse files Browse the repository at this point in the history
Closes #1323
  • Loading branch information
aleclarson committed Jan 3, 2021
1 parent 331484c commit 1da12ba
Showing 1 changed file with 10 additions and 1 deletion.
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

0 comments on commit 1da12ba

Please sign in to comment.