Skip to content

Commit feed5e6

Browse files
refactor: code
1 parent a37713f commit feed5e6

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/index.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -984,35 +984,36 @@ class MiniCssExtractPlugin {
984984
compiler.webpack.sources;
985985
const source = new ConcatSource();
986986
const externalsSource = new ConcatSource();
987-
const includePathinfo = compilation.outputOptions.pathinfo;
988987

989-
for (const m of usedModules) {
990-
let content = m.content.toString();
988+
for (const module of usedModules) {
989+
let content = module.content.toString();
991990

992-
if (includePathinfo) {
991+
const readableIdentifier = module.readableIdentifier(requestShortener);
992+
993+
if (compilation.outputOptions.pathinfo) {
993994
// From https://github.com/webpack/webpack/blob/29eff8a74ecc2f87517b627dee451c2af9ed3f3f/lib/ModuleInfoHeaderPlugin.js#L191-L194
994-
const req = m.readableIdentifier(requestShortener);
995-
const reqStr = req.replace(/\*\//g, "*_/");
995+
const reqStr = readableIdentifier.replace(/\*\//g, "*_/");
996996
const reqStrStar = "*".repeat(reqStr.length);
997997
const headerStr = `/*!****${reqStrStar}****!*\\\n !*** ${reqStr} ***!\n \\****${reqStrStar}****/\n`;
998+
998999
content = headerStr + content;
9991000
}
10001001

10011002
if (/^@import url/.test(content)) {
10021003
// HACK for IE
10031004
// http://stackoverflow.com/a/14676665/1458162
1004-
if (m.media) {
1005+
if (module.media) {
10051006
// insert media into the @import
10061007
// this is rar
10071008
// TODO improve this and parse the CSS to support multiple medias
1008-
content = content.replace(/;|\s*$/, m.media);
1009+
content = content.replace(/;|\s*$/, module.media);
10091010
}
10101011

10111012
externalsSource.add(content);
10121013
externalsSource.add("\n");
10131014
} else {
1014-
if (m.media) {
1015-
source.add(`@media ${m.media} {\n`);
1015+
if (module.media) {
1016+
source.add(`@media ${module.media} {\n`);
10161017
}
10171018

10181019
const { path: filename } = compilation.getPathWithInfo(
@@ -1024,22 +1025,21 @@ class MiniCssExtractPlugin {
10241025

10251026
content = content.replace(new RegExp(AUTO_PUBLIC_PATH, "g"), undoPath);
10261027

1027-
if (m.sourceMap) {
1028+
if (module.sourceMap) {
10281029
source.add(
10291030
new SourceMapSource(
10301031
content,
1031-
m.readableIdentifier(requestShortener),
1032-
m.sourceMap.toString()
1032+
readableIdentifier,
1033+
module.sourceMap.toString()
10331034
)
10341035
);
10351036
} else {
1036-
source.add(
1037-
new RawSource(content, m.readableIdentifier(requestShortener))
1038-
);
1037+
source.add(new RawSource(content, readableIdentifier));
10391038
}
1039+
10401040
source.add("\n");
10411041

1042-
if (m.media) {
1042+
if (module.media) {
10431043
source.add("}\n");
10441044
}
10451045
}

0 commit comments

Comments
 (0)