Skip to content

Commit

Permalink
fix: load source map from sourceMappingURL comment (#1327)
Browse files Browse the repository at this point in the history
..and feed it into the `transform` hook.
  • Loading branch information
aleclarson committed Jan 3, 2021
1 parent 1da12ba commit 1f89b0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/vite/package.json
Expand Up @@ -59,6 +59,7 @@
"@rollup/plugin-typescript": "^8.0.0",
"@rollup/pluginutils": "^4.1.0",
"@types/clean-css": "^4.2.3",
"@types/convert-source-map": "^1.5.1",
"@types/debug": "^4.1.5",
"@types/es-module-lexer": "^0.3.0",
"@types/estree": "^0.0.45",
Expand All @@ -77,6 +78,7 @@
"clean-css": "^4.2.3",
"connect": "^3.7.0",
"connect-history-api-fallback": "^1.6.0",
"convert-source-map": "^1.7.0",
"cors": "^2.8.5",
"debug": "^4.3.1",
"dotenv": "^8.2.0",
Expand Down
10 changes: 9 additions & 1 deletion packages/vite/src/node/server/transformRequest.ts
@@ -1,5 +1,7 @@
import { promises as fs } from 'fs'
import path from 'path'
import getEtag from 'etag'
import * as convertSourceMap from 'convert-source-map'
import { SourceDescription, SourceMap } from 'rollup'
import { ViteDevServer } from '..'
import chalk from 'chalk'
Expand Down Expand Up @@ -58,6 +60,12 @@ export async function transformRequest(
throw e
}
}
if (code) {
map = (
convertSourceMap.fromSource(code) ||
convertSourceMap.fromMapFileSource(code, path.dirname(file))
)?.toObject()
}
} else {
isDebug && debugLoad(`${timeFrom(loadStart)} [plugin] ${prettyUrl}`)
if (typeof loadResult === 'object') {
Expand All @@ -80,7 +88,7 @@ export async function transformRequest(

// transform
const transformStart = Date.now()
const transformResult = await pluginContainer.transform(code, id)
const transformResult = await pluginContainer.transform(code, id, map)
if (
transformResult == null ||
(typeof transformResult === 'object' && transformResult.code == null)
Expand Down

0 comments on commit 1f89b0e

Please sign in to comment.