Skip to content

Commit bc9698c

Browse files
refactor: sourcemap processing
1 parent 8353353 commit bc9698c

11 files changed

+505
-59
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
logs
21
*.log
32
npm-debug.log*
43
.eslintcache

package-lock.json

+172
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"file-loader": "^6.0.0",
7777
"husky": "^4.2.5",
7878
"jest": "^26.1.0",
79+
"less-loader": "^6.2.0",
7980
"lint-staged": "^10.2.11",
8081
"memfs": "^3.2.0",
8182
"mini-css-extract-plugin": "^0.9.0",
@@ -88,6 +89,8 @@
8889
"standard-version": "^8.0.2",
8990
"strip-ansi": "^6.0.0",
9091
"style-loader": "^1.2.1",
92+
"stylus": "^0.54.8",
93+
"stylus-loader": "^3.0.2",
9194
"url-loader": "^4.1.0",
9295
"webpack": "^4.44.0"
9396
},

src/index.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
import path from 'path';
6+
57
import { getOptions, stringifyRequest } from 'loader-utils';
68
import postcss from 'postcss';
79
import postcssPkg from 'postcss/package.json';
@@ -26,6 +28,7 @@ import {
2628
getModulesPlugins,
2729
normalizeSourceMap,
2830
sort,
31+
getSourceMapRelativePath,
2932
} from './utils';
3033

3134
export default async function loader(content, map, meta) {
@@ -151,6 +154,14 @@ export default async function loader(content, map, meta) {
151154
}
152155
}
153156

157+
const sourceMap = map ? normalizeSourceMap(map) : null;
158+
159+
if (sourceMap) {
160+
sourceMap.sources = sourceMap.sources.map((src) =>
161+
getSourceMapRelativePath(src, path.dirname(this.resourcePath))
162+
);
163+
}
164+
154165
let result;
155166

156167
try {
@@ -160,7 +171,7 @@ export default async function loader(content, map, meta) {
160171
map: options.sourceMap
161172
? {
162173
// Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
163-
prev: map ? normalizeSourceMap(map) : null,
174+
prev: sourceMap,
164175
inline: false,
165176
annotation: false,
166177
}
@@ -198,7 +209,14 @@ export default async function loader(content, map, meta) {
198209
}
199210

200211
const importCode = getImportCode(imports, options);
201-
const moduleCode = getModuleCode(result, api, replacements, options);
212+
const moduleCode = getModuleCode(
213+
result,
214+
api,
215+
replacements,
216+
options,
217+
this.resourcePath,
218+
this.rootContext
219+
);
202220
const exportCode = getExportCode(exports, replacements, options);
203221

204222
callback(null, `${importCode}${moduleCode}${exportCode}`);

0 commit comments

Comments
 (0)