MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/ManifestPlugin.js:63–248  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

61 * @returns {void}
62 */
63 apply(compiler) {
64 compiler.hooks.validate.tap(PLUGIN_NAME, () => {
65 compiler.validate(
66 () => require("../schemas/plugins/ManifestPlugin.json"),
67 this.options,
68 {
69 name: "ManifestPlugin",
70 baseDataPath: "options"
71 },
72 (options) => require("../schemas/plugins/ManifestPlugin.check")(options)
73 );
74 });
75
76 const entrypoints =
77 this.options.entrypoints !== undefined ? this.options.entrypoints : true;
78 const serialize =
79 this.options.serialize ||
80 ((manifest) => JSON.stringify(manifest, null, 2));
81
82 compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
83 compilation.hooks.processAssets.tap(
84 {
85 name: PLUGIN_NAME,
86 stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
87 },
88 () => {
89 const hashDigestLength = compilation.outputOptions.hashDigestLength;
90 const publicPath = compilation.getPath(
91 compilation.outputOptions.publicPath
92 );
93
94 /**
95 * Creates a hash reg exp.
96 * @param {string | string[]} value value
97 * @returns {RegExp} regexp to remove hash
98 */
99 const createHashRegExp = (value) =>
100 new RegExp(
101 `(?:\\.${Array.isArray(value) ? `(${value.join("|")})` : value})(?=\\.)`,
102 "gi"
103 );
104
105 /**
106 * Removes the provided name from the manifest plugin.
107 * @param {string} name name
108 * @param {AssetInfo | null} info asset info
109 * @returns {string} hash removed name
110 */
111 const removeHash = (name, info) => {
112 // Handles hashes that match configured `hashDigestLength`
113 // i.e. index.XXXX.html -> index.html (html-webpack-plugin)
114 if (hashDigestLength <= 0) return name;
115 const reg = createHashRegExp(`[a-f0-9]{${hashDigestLength},32}`);
116 return name.replace(reg, "");
117 };
118
119 /**
120 * Returns chunk name or chunk id.

Callers

nothing calls this directly

Calls 12

getNameFunction · 0.85
extnameFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
getPathMethod · 0.80
getParentsMethod · 0.80
getAssetsMethod · 0.80
emitAssetMethod · 0.80
requireFunction · 0.50
serializeFunction · 0.50
pushMethod · 0.45
generateMethod · 0.45

Tested by

no test coverage detected