source: frontend/node_modules/webpack/lib/PrefetchPlugin.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const PrefetchDependency = require("./dependencies/PrefetchDependency");
9
10/** @typedef {import("./Compiler")} Compiler */
11
12const PLUGIN_NAME = "PrefetchPlugin";
13
14class PrefetchPlugin {
15 /**
16 * Creates an instance of PrefetchPlugin.
17 * @param {string} context context or request if context is not set
18 * @param {string=} request request
19 */
20 constructor(context, request) {
21 if (request) {
22 this.context = context;
23 this.request = request;
24 } else {
25 this.context = null;
26 this.request = context;
27 }
28 }
29
30 /**
31 * Applies the plugin by registering its hooks on the compiler.
32 * @param {Compiler} compiler the compiler instance
33 * @returns {void}
34 */
35 apply(compiler) {
36 compiler.hooks.compilation.tap(
37 PLUGIN_NAME,
38 (compilation, { normalModuleFactory }) => {
39 compilation.dependencyFactories.set(
40 PrefetchDependency,
41 normalModuleFactory
42 );
43 }
44 );
45 compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
46 compilation.addModuleChain(
47 this.context || compiler.context,
48 new PrefetchDependency(this.request),
49 (err) => {
50 callback(err);
51 }
52 );
53 });
54 }
55}
56
57module.exports = PrefetchPlugin;
Note: See TracBrowser for help on using the repository browser.