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} */
|
/** @type {boolean} */
|
||||||
this.useSimpleSourceMap = false;
|
this.useSimpleSourceMap = false;
|
||||||
|
|
||||||
// Is hot context
|
// Is in hot context, i.e. HotModuleReplacementPlugin.js enabled
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
this.hot = false;
|
this.hot = false;
|
||||||
// Info from Build
|
// Info from Build
|
||||||
|
|
|
@ -189,7 +189,7 @@ class CssModulesPlugin {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
/** @type {WeakMap<Source, { undoPath: string, inheritance: Inheritance, source: CachedSource }>} */
|
/** @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
|
* @returns {Source} css module source
|
||||||
*/
|
*/
|
||||||
renderModule(module, renderContext, hooks) {
|
renderModule(module, renderContext, hooks) {
|
||||||
const { codeGenerationResults, chunk, undoPath, chunkGraph } =
|
const { codeGenerationResults, chunk, undoPath } = renderContext;
|
||||||
renderContext;
|
|
||||||
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
||||||
const moduleSourceContent =
|
const moduleSourceContent =
|
||||||
/** @type {Source} */
|
/** @type {Source} */
|
||||||
|
@ -726,8 +725,7 @@ class CssModulesPlugin {
|
||||||
codeGenResult.sources.get("css") ||
|
codeGenResult.sources.get("css") ||
|
||||||
codeGenResult.sources.get("css-import")
|
codeGenResult.sources.get("css-import")
|
||||||
);
|
);
|
||||||
|
const cacheEntry = this._moduleFactoryCache.get(moduleSourceContent);
|
||||||
const cacheEntry = this._moduleCache.get(moduleSourceContent);
|
|
||||||
|
|
||||||
/** @type {Inheritance} */
|
/** @type {Inheritance} */
|
||||||
const inheritance = [[module.cssLayer, module.supports, module.media]];
|
const inheritance = [[module.cssLayer, module.supports, module.media]];
|
||||||
|
@ -749,9 +747,9 @@ class CssModulesPlugin {
|
||||||
) {
|
) {
|
||||||
source = cacheEntry.source;
|
source = cacheEntry.source;
|
||||||
} else {
|
} else {
|
||||||
const moduleSourceCode = /** @type {string} */ (
|
const moduleSourceCode =
|
||||||
moduleSourceContent.source()
|
/** @type {string} */
|
||||||
);
|
(moduleSourceContent.source());
|
||||||
const publicPathAutoRegex = new RegExp(
|
const publicPathAutoRegex = new RegExp(
|
||||||
CssUrlDependency.PUBLIC_PATH_AUTO,
|
CssUrlDependency.PUBLIC_PATH_AUTO,
|
||||||
"g"
|
"g"
|
||||||
|
@ -803,18 +801,12 @@ class CssModulesPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
source = new CachedSource(moduleSource);
|
source = new CachedSource(moduleSource);
|
||||||
this._moduleCache.set(moduleSourceContent, {
|
this._moduleFactoryCache.set(moduleSourceContent, {
|
||||||
inheritance,
|
inheritance,
|
||||||
undoPath,
|
undoPath,
|
||||||
source
|
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(
|
return tryRunOrWebpackError(
|
||||||
() => hooks.renderModulePackage.call(source, module, renderContext),
|
() => hooks.renderModulePackage.call(source, module, renderContext),
|
||||||
|
|
Loading…
Reference in New Issue