Skip to content
Permalink
Browse files
fix: respect nosources in the devtool option
  • Loading branch information
alexander-akait committed Oct 26, 2021
1 parent 897e7dd commit c60eff212337c8a65995f6675d25f49bb515e77d
Showing with 1,324 additions and 973 deletions.
  1. +22 −4 src/utils.js
  2. +424 −246 test/__snapshots__/sourceMap-option.test.js.snap
  3. +878 −723 test/sourceMap-option.test.js
@@ -929,8 +929,19 @@ function normalizeSourceMapForRuntime(map, loaderContext) {
if (resultMap) {
delete resultMap.file;

resultMap.sourceRoot = "";
/* eslint-disable no-underscore-dangle */
if (
loaderContext._compilation &&
loaderContext._compilation.options &&
loaderContext._compilation.options.devtool &&
loaderContext._compilation.options.devtool.includes("nosources")
) {
/* eslint-enable no-underscore-dangle */

delete resultMap.sourcesContent;
}

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

const sourceMapValue = options.sourceMap
? `,${normalizeSourceMapForRuntime(result.map, loaderContext)}`
: "";
let sourceMapValue = "";

if (options.sourceMap) {
const sourceMap = result.map;

sourceMapValue = `,${normalizeSourceMapForRuntime(
sourceMap,
loaderContext
)}`;
}

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

0 comments on commit c60eff2

Please sign in to comment.