feat: refactoring project
This commit is contained in:
55
node_modules/webpack/lib/asset/AssetModulesPlugin.js
generated
vendored
55
node_modules/webpack/lib/asset/AssetModulesPlugin.js
generated
vendored
@@ -17,9 +17,12 @@ const createSchemaValidation = require("../util/create-schema-validation");
|
||||
const memoize = require("../util/memoize");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
||||
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
||||
|
||||
/**
|
||||
* @param {string} name name of definitions
|
||||
@@ -89,7 +92,8 @@ class AssetModulesPlugin {
|
||||
.tap(plugin, parserOptions => {
|
||||
validateParserOptions(parserOptions);
|
||||
parserOptions = cleverMerge(
|
||||
compiler.options.module.parser.asset,
|
||||
/** @type {AssetParserOptions} */
|
||||
(compiler.options.module.parser.asset),
|
||||
parserOptions
|
||||
);
|
||||
|
||||
@@ -107,21 +111,21 @@ class AssetModulesPlugin {
|
||||
});
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for(ASSET_MODULE_TYPE_INLINE)
|
||||
.tap(plugin, parserOptions => {
|
||||
.tap(plugin, _parserOptions => {
|
||||
const AssetParser = getAssetParser();
|
||||
|
||||
return new AssetParser(true);
|
||||
});
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for(ASSET_MODULE_TYPE_RESOURCE)
|
||||
.tap(plugin, parserOptions => {
|
||||
.tap(plugin, _parserOptions => {
|
||||
const AssetParser = getAssetParser();
|
||||
|
||||
return new AssetParser(false);
|
||||
});
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for(ASSET_MODULE_TYPE_SOURCE)
|
||||
.tap(plugin, parserOptions => {
|
||||
.tap(plugin, _parserOptions => {
|
||||
const AssetSourceParser = getAssetSourceParser();
|
||||
|
||||
return new AssetSourceParser();
|
||||
@@ -137,7 +141,7 @@ class AssetModulesPlugin {
|
||||
.tap(plugin, generatorOptions => {
|
||||
validateGeneratorOptions[type](generatorOptions);
|
||||
|
||||
let dataUrl = undefined;
|
||||
let dataUrl;
|
||||
if (type !== ASSET_MODULE_TYPE_RESOURCE) {
|
||||
dataUrl = generatorOptions.dataUrl;
|
||||
if (!dataUrl || typeof dataUrl === "object") {
|
||||
@@ -149,9 +153,9 @@ class AssetModulesPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
let filename = undefined;
|
||||
let publicPath = undefined;
|
||||
let outputPath = undefined;
|
||||
let filename;
|
||||
let publicPath;
|
||||
let outputPath;
|
||||
if (type !== ASSET_MODULE_TYPE_INLINE) {
|
||||
filename = generatorOptions.filename;
|
||||
publicPath = generatorOptions.publicPath;
|
||||
@@ -161,6 +165,7 @@ class AssetModulesPlugin {
|
||||
const AssetGenerator = getAssetGenerator();
|
||||
|
||||
return new AssetGenerator(
|
||||
compilation.moduleGraph,
|
||||
dataUrl,
|
||||
filename,
|
||||
publicPath,
|
||||
@@ -174,7 +179,7 @@ class AssetModulesPlugin {
|
||||
.tap(plugin, () => {
|
||||
const AssetSourceGenerator = getAssetSourceGenerator();
|
||||
|
||||
return new AssetSourceGenerator();
|
||||
return new AssetSourceGenerator(compilation.moduleGraph);
|
||||
});
|
||||
|
||||
compilation.hooks.renderManifest.tap(plugin, (result, options) => {
|
||||
@@ -193,24 +198,23 @@ class AssetModulesPlugin {
|
||||
module,
|
||||
chunk.runtime
|
||||
);
|
||||
const buildInfo = /** @type {BuildInfo} */ (module.buildInfo);
|
||||
const data =
|
||||
/** @type {NonNullable<CodeGenerationResult["data"]>} */
|
||||
(codeGenResult.data);
|
||||
result.push({
|
||||
render: () => codeGenResult.sources.get(type),
|
||||
filename:
|
||||
module.buildInfo.filename ||
|
||||
codeGenResult.data.get("filename"),
|
||||
info:
|
||||
module.buildInfo.assetInfo ||
|
||||
codeGenResult.data.get("assetInfo"),
|
||||
render: () =>
|
||||
/** @type {Source} */ (codeGenResult.sources.get(type)),
|
||||
filename: buildInfo.filename || data.get("filename"),
|
||||
info: buildInfo.assetInfo || data.get("assetInfo"),
|
||||
auxiliary: true,
|
||||
identifier: `assetModule${chunkGraph.getModuleId(module)}`,
|
||||
hash:
|
||||
module.buildInfo.fullContentHash ||
|
||||
codeGenResult.data.get("fullContentHash")
|
||||
hash: buildInfo.fullContentHash || data.get("fullContentHash")
|
||||
});
|
||||
} catch (e) {
|
||||
/** @type {Error} */ (e).message +=
|
||||
} catch (err) {
|
||||
/** @type {Error} */ (err).message +=
|
||||
`\nduring rendering of asset ${module.identifier()}`;
|
||||
throw e;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,9 +228,12 @@ class AssetModulesPlugin {
|
||||
const { codeGenerationResult } = options;
|
||||
const source = codeGenerationResult.sources.get(ASSET_MODULE_TYPE);
|
||||
if (source === undefined) return;
|
||||
context.assets.set(codeGenerationResult.data.get("filename"), {
|
||||
const data =
|
||||
/** @type {NonNullable<CodeGenerationResult["data"]>} */
|
||||
(codeGenerationResult.data);
|
||||
context.assets.set(data.get("filename"), {
|
||||
source,
|
||||
info: codeGenerationResult.data.get("assetInfo")
|
||||
info: data.get("assetInfo")
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user