Skip to content

Commit 32d88c6

Browse files
committed
fix: remove loaded input sourcemap (fixes vitejs#8411)
1 parent f937ccc commit 32d88c6

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed

packages/vite/src/node/server/pluginContainer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ export async function createPluginContainer(
472472
this.filename = filename
473473
this.originalCode = code
474474
if (inMap) {
475+
if (isDebugSourcemapCombineFocused) {
476+
// @ts-expect-error inject name for debug purpose
477+
inMap.name = '$inMap'
478+
}
475479
this.sourcemapChain.push(inMap)
476480
}
477481
}

packages/vite/src/node/server/transformRequest.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { SourceDescription, SourceMap } from 'rollup'
77
import colors from 'picocolors'
88
import type { ViteDevServer } from '..'
99
import {
10+
blankReplacer,
1011
cleanUrl,
1112
createDebugger,
1213
ensureWatchedFile,
@@ -196,6 +197,8 @@ async function loadAndTransform(
196197
convertSourceMap.fromSource(code) ||
197198
convertSourceMap.fromMapFileSource(code, path.dirname(file))
198199
)?.toObject()
200+
201+
code = code.replace(convertSourceMap.mapFileCommentRegex, blankReplacer)
199202
} catch (e) {
200203
logger.warn(`Failed to load source map for ${url}.`, {
201204
timestamp: true

playground/css-sourcemap/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ <h1>CSS Sourcemap</h1>
2626
<p class="imported-stylus">&lt;imported stylus&gt;</p>
2727

2828
<p class="imported-sugarss">&lt;imported sugarss&gt;</p>
29+
30+
<p class="input-map">&lt;input source-map&gt;</p>
2931
</div>
3032

3133
<script type="module">
@@ -44,6 +46,8 @@ <h1>CSS Sourcemap</h1>
4446
import './imported.styl'
4547

4648
import './imported.sss'
49+
50+
import './input-map.css'
4751
</script>
4852

4953
<iframe src="virtual.html"></iframe>

playground/css-sourcemap/input-map.css

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground/css-sourcemap/input-map.css.map

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.input-map {
2+
color: blue;
3+
}

0 commit comments

Comments
 (0)