Avoid deopt when cache is set

This commit is contained in:
Florent Cailhol 2018-04-10 23:24:22 +02:00
parent 55fb1da193
commit 6e154f650a
2 changed files with 14 additions and 4 deletions

View File

@ -6,6 +6,7 @@
const { RawSource } = require("webpack-sources");
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
const cache = new WeakMap();
class EvalDevToolModuleTemplatePlugin {

View File

@ -7,6 +7,8 @@
const { RawSource } = require("webpack-sources");
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
const cache = new WeakMap();
class EvalSourceMapDevToolModuleTemplatePlugin {
constructor(compilation, options) {
this.compilation = compilation;
@ -29,8 +31,11 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
moduleTemplate.hooks.module.tap(
"EvalSourceMapDevToolModuleTemplatePlugin",
(source, module) => {
if (source.__EvalSourceMapDevToolData)
return source.__EvalSourceMapDevToolData;
const cachedSource = cache.get(source);
if (cachedSource !== undefined) {
return cachedSource;
}
if (!matchModule(module.resource)) {
return source;
}
@ -87,10 +92,14 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
"utf8"
).toString("base64")}`
) + `\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
source.__EvalSourceMapDevToolData = new RawSource(
const evalSource = new RawSource(
`eval(${JSON.stringify(content + footer)});`
);
return source.__EvalSourceMapDevToolData;
cache.set(source, evalSource);
return evalSource;
}
);
moduleTemplate.hooks.hash.tap(