Skip to content
Merged
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
17 changes: 15 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Author Tobias Koppers @sokra
*/

import crypto from "crypto";
import path from "path";

import webpack, {
Expand All @@ -15,6 +14,20 @@ import serialize from "serialize-javascript";

import schema from "./options.json";

const internalCreateHash = (algorithm) => {
try {
// eslint-disable-next-line global-require import/no-unresolved
const createHash = require("webpack/lib/util/createHash");

return createHash(algorithm);
} catch (err) {
// Ignore
}

return require("crypto").createHash(algorithm);
};


const { RawSource } =
// eslint-disable-next-line global-require
webpack.sources || require("webpack-sources");
Expand Down Expand Up @@ -229,7 +242,7 @@ class CompressionPlugin {
originalAlgorithm: this.options.algorithm,
compressionOptions: this.options.compressionOptions,
name,
contentHash: crypto.createHash("md4").update(input).digest("hex"),
contentHash: internalCreateHash("md4").update(input).digest("hex"),
};
} else {
cacheData.name = serialize({
Expand Down