source: imaps-frontend/node_modules/webpack/lib/AutomaticPrefetchPlugin.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[79a0317]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const asyncLib = require("neo-async");
9const NormalModule = require("./NormalModule");
10const PrefetchDependency = require("./dependencies/PrefetchDependency");
11
12/** @typedef {import("./Compiler")} Compiler */
13
14class AutomaticPrefetchPlugin {
15 /**
16 * Apply the plugin
17 * @param {Compiler} compiler the compiler instance
18 * @returns {void}
19 */
20 apply(compiler) {
21 compiler.hooks.compilation.tap(
22 "AutomaticPrefetchPlugin",
23 (compilation, { normalModuleFactory }) => {
24 compilation.dependencyFactories.set(
25 PrefetchDependency,
26 normalModuleFactory
27 );
28 }
29 );
30 /** @type {{context: string | null, request: string}[] | null} */
31 let lastModules = null;
32 compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
33 lastModules = [];
34
35 for (const m of compilation.modules) {
36 if (m instanceof NormalModule) {
37 lastModules.push({
38 context: m.context,
39 request: m.request
40 });
41 }
42 }
43 });
44 compiler.hooks.make.tapAsync(
45 "AutomaticPrefetchPlugin",
46 (compilation, callback) => {
47 if (!lastModules) return callback();
48 asyncLib.each(
49 lastModules,
50 (m, callback) => {
51 compilation.addModuleChain(
52 m.context || compiler.context,
53 new PrefetchDependency(`!!${m.request}`),
54 callback
55 );
56 },
57 err => {
58 lastModules = null;
59 callback(err);
60 }
61 );
62 }
63 );
64 }
65}
66module.exports = AutomaticPrefetchPlugin;
Note: See TracBrowser for help on using the repository browser.