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

Method apply

lib/dll/DllReferencePlugin.js:42–180  ·  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

40 * @returns {void}
41 */
42 apply(compiler) {
43 compiler.hooks.validate.tap(PLUGIN_NAME, () => {
44 compiler.validate(
45 () => require("../../schemas/plugins/dll/DllReferencePlugin.json"),
46 this.options,
47 {
48 name: "Dll Reference Plugin",
49 baseDataPath: "options"
50 },
51 (options) =>
52 require("../../schemas/plugins/dll/DllReferencePlugin.check")(options)
53 );
54 });
55 compiler.hooks.compilation.tap(
56 PLUGIN_NAME,
57 (compilation, { normalModuleFactory }) => {
58 compilation.dependencyFactories.set(
59 DelegatedSourceDependency,
60 normalModuleFactory
61 );
62 }
63 );
64
65 /** @type {WeakMap<CompilationParams, CompilationDataItem>} */
66 const compilationData = new WeakMap();
67
68 compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => {
69 if ("manifest" in this.options) {
70 const manifest = this.options.manifest;
71 if (typeof manifest === "string") {
72 /** @type {InputFileSystem} */
73 (compiler.inputFileSystem).readFile(manifest, (err, result) => {
74 if (err) return callback(err);
75 /** @type {CompilationDataItem} */
76 const data = {
77 path: manifest,
78 data: undefined,
79 error: undefined
80 };
81 // Catch errors parsing the manifest so that blank
82 // or malformed manifest files don't kill the process.
83 try {
84 data.data =
85 /** @type {DllReferencePluginOptionsManifest} */
86 (
87 /** @type {unknown} */
88 (parseJson(/** @type {Buffer} */ (result).toString("utf8")))
89 );
90 } catch (parseErr) {
91 // Store the error in the params so that it can
92 // be added as a compilation error later on.
93 const manifestPath = makePathsRelative(
94 compiler.context,
95 manifest,
96 compiler.root
97 );
98 data.error = new DllManifestError(
99 manifestPath,

Callers

nothing calls this directly

Calls 12

parseJsonFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
readFileMethod · 0.80
applyMethod · 0.65
requireFunction · 0.50
callbackFunction · 0.50
setMethod · 0.45
toStringMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected