Skip to content

Commit

Permalink
fix: remove loaded input sourcemap (fixes vitejs#8411)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Oct 29, 2022
1 parent f937ccc commit 32d88c6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/vite/src/node/server/pluginContainer.ts
Expand Up @@ -472,6 +472,10 @@ export async function createPluginContainer(
this.filename = filename
this.originalCode = code
if (inMap) {
if (isDebugSourcemapCombineFocused) {
// @ts-expect-error inject name for debug purpose
inMap.name = '$inMap'
}
this.sourcemapChain.push(inMap)
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/node/server/transformRequest.ts
Expand Up @@ -7,6 +7,7 @@ import type { SourceDescription, SourceMap } from 'rollup'
import colors from 'picocolors'
import type { ViteDevServer } from '..'
import {
blankReplacer,
cleanUrl,
createDebugger,
ensureWatchedFile,
Expand Down Expand Up @@ -196,6 +197,8 @@ async function loadAndTransform(
convertSourceMap.fromSource(code) ||
convertSourceMap.fromMapFileSource(code, path.dirname(file))
)?.toObject()

code = code.replace(convertSourceMap.mapFileCommentRegex, blankReplacer)
} catch (e) {
logger.warn(`Failed to load source map for ${url}.`, {
timestamp: true
Expand Down
4 changes: 4 additions & 0 deletions playground/css-sourcemap/index.html
Expand Up @@ -26,6 +26,8 @@ <h1>CSS Sourcemap</h1>
<p class="imported-stylus">&lt;imported stylus&gt;</p>

<p class="imported-sugarss">&lt;imported sugarss&gt;</p>

<p class="input-map">&lt;input source-map&gt;</p>
</div>

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

import './imported.sss'

import './input-map.css'
</script>

<iframe src="virtual.html"></iframe>
4 changes: 4 additions & 0 deletions playground/css-sourcemap/input-map.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions playground/css-sourcemap/input-map.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions playground/css-sourcemap/input-map.src.css
@@ -0,0 +1,3 @@
.input-map {
color: blue;
}

0 comments on commit 32d88c6

Please sign in to comment.