Skip to content

Commit f813b4c

Browse files
fix: source map generation with pathinfo (#817)
1 parent c6c18a6 commit f813b4c

File tree

8 files changed

+69
-1
lines changed

8 files changed

+69
-1
lines changed

src/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -991,16 +991,22 @@ class MiniCssExtractPlugin {
991991
const readableIdentifier = module.readableIdentifier(requestShortener);
992992
const startsWithAtRuleImport = /^@import url/.test(content);
993993

994+
let header;
995+
994996
if (compilation.outputOptions.pathinfo) {
995997
// From https://github.com/webpack/webpack/blob/29eff8a74ecc2f87517b627dee451c2af9ed3f3f/lib/ModuleInfoHeaderPlugin.js#L191-L194
996998
const reqStr = readableIdentifier.replace(/\*\//g, "*_/");
997999
const reqStrStar = "*".repeat(reqStr.length);
9981000
const headerStr = `/*!****${reqStrStar}****!*\\\n !*** ${reqStr} ***!\n \\****${reqStrStar}****/\n`;
9991001

1000-
content = headerStr + content;
1002+
header = new RawSource(headerStr);
10011003
}
10021004

10031005
if (startsWithAtRuleImport) {
1006+
if (typeof header !== "undefined") {
1007+
externalsSource.add(header);
1008+
}
1009+
10041010
// HACK for IE
10051011
// http://stackoverflow.com/a/14676665/1458162
10061012
if (module.media) {
@@ -1013,6 +1019,10 @@ class MiniCssExtractPlugin {
10131019
externalsSource.add(content);
10141020
externalsSource.add("\n");
10151021
} else {
1022+
if (typeof header !== "undefined") {
1023+
source.add(header);
1024+
}
1025+
10161026
if (module.media) {
10171027
source.add(`@media ${module.media} {\n`);
10181028
}

test/cases/pathinfo-devtool-source-map/expected/main.css

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

test/cases/pathinfo-devtool-source-map/expected/main.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: yellow;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./style.css";
2+
import "./other.css";
3+
import "./extra.css";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: blue;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Self from "../../../src";
2+
3+
module.exports = {
4+
entry: "./index.js",
5+
devtool: "source-map",
6+
output: {
7+
pathinfo: true,
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: /\.css$/,
13+
use: [Self.loader, "css-loader"],
14+
},
15+
],
16+
},
17+
plugins: [
18+
new Self({
19+
filename: "[name].css",
20+
}),
21+
],
22+
};

0 commit comments

Comments
 (0)