Skip to content

Commit b5e011b

Browse files
test: check
1 parent 639ac56 commit b5e011b

File tree

4 files changed

+171
-703
lines changed

4 files changed

+171
-703
lines changed

src/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Author Tobias Koppers @sokra
44
*/
55
import validateOptions from 'schema-utils';
6+
import RequestShortener from 'webpack/lib/RequestShortener';
67
import postcss from 'postcss';
78
import postcssPkg from 'postcss/package.json';
89

@@ -76,7 +77,13 @@ export default function loader(content, map, meta) {
7677
map: options.sourceMap
7778
? {
7879
// Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
79-
prev: sourceMap && map ? normalizeSourceMap(map) : null,
80+
prev:
81+
sourceMap && map
82+
? normalizeSourceMap(
83+
map,
84+
new RequestShortener(this.rootContext)
85+
)
86+
: null,
8087
inline: false,
8188
annotation: false,
8289
}

src/utils.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,35 @@ function getModulesPlugins(options, loaderContext) {
156156
];
157157
}
158158

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

162162
// Some loader emit source map as string
163-
// Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
164163
if (typeof newMap === 'string') {
165164
newMap = JSON.parse(newMap);
166165
}
167166

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

171172
if (newMap.file) {
172-
newMap.file = normalizePath(newMap.file);
173+
newMap.file = requestShortener.shorten(newMap.file);
173174
}
174175

175176
if (newMap.sourceRoot) {
176-
newMap.sourceRoot = normalizePath(newMap.sourceRoot);
177+
newMap.sourceRoot = requestShortener.shorten(newMap.sourceRoot);
177178
}
178179

179180
if (newMap.sources) {
180-
newMap.sources = newMap.sources.map((source) => normalizePath(source));
181+
newMap.sources = newMap.sources.map((source) =>
182+
requestShortener.shorten(source)
183+
);
181184
}
182185

186+
console.log(newMap);
187+
183188
return newMap;
184189
}
185190

0 commit comments

Comments
 (0)