1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const PrefetchDependency = require("./dependencies/PrefetchDependency");
|
9 |
|
10 |
|
11 |
|
12 | class PrefetchPlugin {
|
13 | constructor(context, request) {
|
14 | if (request) {
|
15 | this.context = context;
|
16 | this.request = request;
|
17 | } else {
|
18 | this.context = null;
|
19 | this.request = context;
|
20 | }
|
21 | }
|
22 |
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 | apply(compiler) {
|
29 | compiler.hooks.compilation.tap(
|
30 | "PrefetchPlugin",
|
31 | (compilation, { normalModuleFactory }) => {
|
32 | compilation.dependencyFactories.set(
|
33 | PrefetchDependency,
|
34 | normalModuleFactory
|
35 | );
|
36 | }
|
37 | );
|
38 | compiler.hooks.make.tapAsync("PrefetchPlugin", (compilation, callback) => {
|
39 | compilation.addModuleChain(
|
40 | this.context || compiler.context,
|
41 | new PrefetchDependency(this.request),
|
42 | err => {
|
43 | callback(err);
|
44 | }
|
45 | );
|
46 | });
|
47 | }
|
48 | }
|
49 |
|
50 | module.exports = PrefetchPlugin;
|