Skip to content

Commit 5c5302c

Browse files
test: check
1 parent 639ac56 commit 5c5302c

File tree

4 files changed

+17
-727
lines changed

4 files changed

+17
-727
lines changed

src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ export default function loader(content, map, meta) {
7676
map: options.sourceMap
7777
? {
7878
// Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
79-
prev: sourceMap && map ? normalizeSourceMap(map) : null,
79+
prev:
80+
sourceMap && map
81+
? normalizeSourceMap(map, this.rootContext)
82+
: null,
8083
inline: false,
8184
annotation: false,
8285
}

src/utils.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function getModulesPlugins(options, loaderContext) {
156156
];
157157
}
158158

159-
function normalizeSourceMap(map) {
159+
function normalizeSourceMap(map, rootContext) {
160160
let newMap = map;
161161

162162
// Some loader emit source map as string
@@ -165,21 +165,29 @@ function normalizeSourceMap(map) {
165165
newMap = JSON.parse(newMap);
166166
}
167167

168+
console.log(newMap);
169+
168170
// Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
169171
// We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
170172

171173
if (newMap.file) {
172-
newMap.file = normalizePath(newMap.file);
174+
newMap.file = normalizePath(path.relative(rootContext, newMap.file));
173175
}
174176

175177
if (newMap.sourceRoot) {
176-
newMap.sourceRoot = normalizePath(newMap.sourceRoot);
178+
newMap.sourceRoot = normalizePath(
179+
path.relative(rootContext, newMap.sourceRoot)
180+
);
177181
}
178182

179183
if (newMap.sources) {
180-
newMap.sources = newMap.sources.map((source) => normalizePath(source));
184+
newMap.sources = newMap.sources.map((source) =>
185+
normalizePath(path.relative(rootContext, source))
186+
);
181187
}
182188

189+
console.log(newMap);
190+
183191
return newMap;
184192
}
185193

0 commit comments

Comments
 (0)