Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,20 @@ class MiniCssExtractPlugin {
compiler.webpack.sources;
const source = new ConcatSource();
const externalsSource = new ConcatSource();
const includePathinfo = compilation.outputOptions.pathinfo;

for (const m of usedModules) {
let content = m.content.toString();

if (includePathinfo) {
// From https://github.com/webpack/webpack/blob/29eff8a74ecc2f87517b627dee451c2af9ed3f3f/lib/ModuleInfoHeaderPlugin.js#L191-L194
const req = m.readableIdentifier(requestShortener);
const reqStr = req.replace(/\*\//g, "*_/");
const reqStrStar = "*".repeat(reqStr.length);
const headerStr = `/*!****${reqStrStar}****!*\\\n !*** ${reqStr} ***!\n \\****${reqStrStar}****/\n`;
content = headerStr + content;
}

if (/^@import url/.test(content)) {
// HACK for IE
// http://stackoverflow.com/a/14676665/1458162
Expand Down
57 changes: 57 additions & 0 deletions test/pathinfo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import path from "path";

import MiniCssExtractPlugin from "../src/cjs";

import { compile, getCompiler } from "./helpers/index";

describe("pathinfo option", () => {
it(`should insert pathinfo`, async () => {
const compiler = getCompiler(
"esm.js",
{},
{
mode: "none",
output: {
pathinfo: true,
path: path.resolve(__dirname, "../outputs"),
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
],
}
);
const stats = await compile(compiler);
const fs = stats.compilation.compiler.outputFileSystem;
const extractedCss = fs
.readFileSync(path.resolve(__dirname, "../outputs/main.css"))
.toString();

expect(extractedCss).toMatch("./simple.css");
});
it(`should not insert pathinfo`, async () => {
const compiler = getCompiler(
"esm.js",
{},
{
mode: "none",
output: {
path: path.resolve(__dirname, "../outputs"),
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
],
}
);
const stats = await compile(compiler);
const fs = stats.compilation.compiler.outputFileSystem;
const extractedCss = fs
.readFileSync(path.resolve(__dirname, "../outputs/main.css"))
.toString();

expect(extractedCss).not.toMatch("./simple.css");
});
});