Skip to content

Commit

Permalink
fix: respect nosources in the devtool option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Oct 26, 2021
1 parent 897e7dd commit c60eff2
Show file tree
Hide file tree
Showing 3 changed files with 1,324 additions and 973 deletions.
26 changes: 22 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit c60eff2

Please sign in to comment.