mirror of https://github.com/webpack/webpack.git
refactor: code
This commit is contained in:
parent
b475c53b81
commit
d5f19bf9a4
|
@ -200,7 +200,7 @@ class Module extends DependenciesBlock {
|
|||
/** @type {boolean} */
|
||||
this.useSimpleSourceMap = false;
|
||||
|
||||
// Is hot context
|
||||
// Is in hot context, i.e. HotModuleReplacementPlugin.js enabled
|
||||
/** @type {boolean} */
|
||||
this.hot = false;
|
||||
// Info from Build
|
||||
|
|
|
@ -189,7 +189,7 @@ class CssModulesPlugin {
|
|||
|
||||
constructor() {
|
||||
/** @type {WeakMap<Source, { undoPath: string, inheritance: Inheritance, source: CachedSource }>} */
|
||||
this._moduleCache = new WeakMap();
|
||||
this._moduleFactoryCache = new WeakMap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -717,8 +717,7 @@ class CssModulesPlugin {
|
|||
* @returns {Source} css module source
|
||||
*/
|
||||
renderModule(module, renderContext, hooks) {
|
||||
const { codeGenerationResults, chunk, undoPath, chunkGraph } =
|
||||
renderContext;
|
||||
const { codeGenerationResults, chunk, undoPath } = renderContext;
|
||||
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
||||
const moduleSourceContent =
|
||||
/** @type {Source} */
|
||||
|
@ -726,8 +725,7 @@ class CssModulesPlugin {
|
|||
codeGenResult.sources.get("css") ||
|
||||
codeGenResult.sources.get("css-import")
|
||||
);
|
||||
|
||||
const cacheEntry = this._moduleCache.get(moduleSourceContent);
|
||||
const cacheEntry = this._moduleFactoryCache.get(moduleSourceContent);
|
||||
|
||||
/** @type {Inheritance} */
|
||||
const inheritance = [[module.cssLayer, module.supports, module.media]];
|
||||
|
@ -749,9 +747,9 @@ class CssModulesPlugin {
|
|||
) {
|
||||
source = cacheEntry.source;
|
||||
} else {
|
||||
const moduleSourceCode = /** @type {string} */ (
|
||||
moduleSourceContent.source()
|
||||
);
|
||||
const moduleSourceCode =
|
||||
/** @type {string} */
|
||||
(moduleSourceContent.source());
|
||||
const publicPathAutoRegex = new RegExp(
|
||||
CssUrlDependency.PUBLIC_PATH_AUTO,
|
||||
"g"
|
||||
|
@ -803,18 +801,12 @@ class CssModulesPlugin {
|
|||
}
|
||||
|
||||
source = new CachedSource(moduleSource);
|
||||
this._moduleCache.set(moduleSourceContent, {
|
||||
this._moduleFactoryCache.set(moduleSourceContent, {
|
||||
inheritance,
|
||||
undoPath,
|
||||
source
|
||||
});
|
||||
}
|
||||
let moduleId = String(chunkGraph.getModuleId(module));
|
||||
|
||||
// When `optimization.moduleIds` is `named` the module id is a path, so we need to normalize it between platforms
|
||||
if (typeof moduleId === "string") {
|
||||
moduleId = moduleId.replace(/\\/g, "/");
|
||||
}
|
||||
|
||||
return tryRunOrWebpackError(
|
||||
() => hooks.renderModulePackage.call(source, module, renderContext),
|
||||
|
|
Loading…
Reference in New Issue