Skip to content

Commit c60eff2

Browse files
authoredOct 26, 2021
fix: respect nosources in the devtool option
1 parent 897e7dd commit c60eff2

File tree

3 files changed

+1324
-973
lines changed

3 files changed

+1324
-973
lines changed
 

‎src/utils.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,19 @@ function normalizeSourceMapForRuntime(map, loaderContext) {
929929
if (resultMap) {
930930
delete resultMap.file;
931931

932-
resultMap.sourceRoot = "";
932+
/* eslint-disable no-underscore-dangle */
933+
if (
934+
loaderContext._compilation &&
935+
loaderContext._compilation.options &&
936+
loaderContext._compilation.options.devtool &&
937+
loaderContext._compilation.options.devtool.includes("nosources")
938+
) {
939+
/* eslint-enable no-underscore-dangle */
940+
941+
delete resultMap.sourcesContent;
942+
}
933943

944+
resultMap.sourceRoot = "";
934945
resultMap.sources = resultMap.sources.map((source) => {
935946
// Non-standard syntax from `postcss`
936947
if (source.indexOf("<") === 0) {
@@ -989,9 +1000,16 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
9891000
return "";
9901001
}
9911002

992-
const sourceMapValue = options.sourceMap
993-
? `,${normalizeSourceMapForRuntime(result.map, loaderContext)}`
994-
: "";
1003+
let sourceMapValue = "";
1004+
1005+
if (options.sourceMap) {
1006+
const sourceMap = result.map;
1007+
1008+
sourceMapValue = `,${normalizeSourceMapForRuntime(
1009+
sourceMap,
1010+
loaderContext
1011+
)}`;
1012+
}
9951013

9961014
let code = JSON.stringify(result.css);
9971015

0 commit comments

Comments
 (0)