Skip to content

Commit f64de13

Browse files
authoredApr 24, 2020
fix: avoid query string in source maps (#1082)
1 parent 841423f commit f64de13

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed
 

‎src/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export default function loader(content, map, meta) {
8282

8383
postcss(plugins)
8484
.process(content, {
85-
from: this.remainingRequest.split('!').pop(),
86-
to: this.currentRequest.split('!').pop(),
85+
from: this.resourcePath,
86+
to: this.resourcePath,
8787
map: options.sourceMap
8888
? {
8989
// Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
@@ -151,8 +151,6 @@ export default function loader(content, map, meta) {
151151
})
152152
.catch((error) => {
153153
if (error.file) {
154-
console.log(error.file);
155-
156154
this.addDependency(error.file);
157155
}
158156

‎test/__snapshots__/sourceMap-option.test.js.snap

+43
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,49 @@ Array [
294294

295295
exports[`"sourceMap" option not specified should not generate source maps: warnings 1`] = `Array []`;
296296

297+
exports[`"sourceMap" option true should generate source maps #2: errors 1`] = `Array []`;
298+
299+
exports[`"sourceMap" option true should generate source maps #2: module 1`] = `
300+
"// Imports
301+
var ___CSS_LOADER_API_IMPORT___ = require(\\"../../../src/runtime/api.js\\");
302+
exports = ___CSS_LOADER_API_IMPORT___(true);
303+
// Module
304+
exports.push([module.id, \\".foo {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"with-query.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA;EACE,UAAU;AACZ\\",\\"file\\":\\"with-query.css\\",\\"sourcesContent\\":[\\".foo {\\\\n color: red;\\\\n}\\\\n\\"]}]);
305+
// Exports
306+
module.exports = exports;
307+
"
308+
`;
309+
310+
exports[`"sourceMap" option true should generate source maps #2: result 1`] = `
311+
Array [
312+
Array [
313+
"./source-map/with-query.css?url=false",
314+
".foo {
315+
color: red;
316+
}
317+
",
318+
"",
319+
Object {
320+
"file": "with-query.css",
321+
"mappings": "AAAA;EACE,UAAU;AACZ",
322+
"names": Array [],
323+
"sources": Array [
324+
"with-query.css",
325+
],
326+
"sourcesContent": Array [
327+
".foo {
328+
color: red;
329+
}
330+
",
331+
],
332+
"version": 3,
333+
},
334+
],
335+
]
336+
`;
337+
338+
exports[`"sourceMap" option true should generate source maps #2: warnings 1`] = `Array []`;
339+
297340
exports[`"sourceMap" option true should generate source maps when source maps equal to "null" from an other loader: errors 1`] = `Array []`;
298341

299342
exports[`"sourceMap" option true should generate source maps when source maps equal to "null" from an other loader: module 1`] = `
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: red;
3+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import css from './with-query.css?url=false';
2+
3+
__export__ = css;
4+
5+
export default css;

‎test/sourceMap-option.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ describe('"sourceMap" option', () => {
4545
expect(getErrors(stats)).toMatchSnapshot('errors');
4646
});
4747

48+
it('should generate source maps #2', async () => {
49+
const compiler = getCompiler('./source-map/with-query.js', {
50+
sourceMap: true,
51+
});
52+
const stats = await compile(compiler);
53+
54+
expect(
55+
getModuleSource('./source-map/with-query.css?url=false', stats)
56+
).toMatchSnapshot('module');
57+
expect(
58+
getExecutedCode('main.bundle.js', compiler, stats)
59+
).toMatchSnapshot('result');
60+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
61+
expect(getErrors(stats)).toMatchSnapshot('errors');
62+
});
63+
4864
it('should generate source maps when source maps equal to "null" from an other loader', async () => {
4965
const compiler = getCompiler(
5066
'./source-map/basic.js',

0 commit comments

Comments
 (0)
Please sign in to comment.