Avoid deopt when cache is set
This commit is contained in:
parent
55fb1da193
commit
6e154f650a
|
@ -6,6 +6,7 @@
|
|||
|
||||
const { RawSource } = require("webpack-sources");
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
|
||||
const cache = new WeakMap();
|
||||
|
||||
class EvalDevToolModuleTemplatePlugin {
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue