1 |
3a515b92
|
cagy
|
/*
|
2 |
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3 |
|
|
Author Tobias Koppers @sokra
|
4 |
|
|
*/
|
5 |
|
|
"use strict";
|
6 |
|
|
const PrefetchDependency = require("./dependencies/PrefetchDependency");
|
7 |
|
|
|
8 |
|
|
class PrefetchPlugin {
|
9 |
|
|
constructor(context, request) {
|
10 |
|
|
if (!request) {
|
11 |
|
|
this.request = context;
|
12 |
|
|
} else {
|
13 |
|
|
this.context = context;
|
14 |
|
|
this.request = request;
|
15 |
|
|
}
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
apply(compiler) {
|
19 |
|
|
compiler.hooks.compilation.tap(
|
20 |
|
|
"PrefetchPlugin",
|
21 |
|
|
(compilation, { normalModuleFactory }) => {
|
22 |
|
|
compilation.dependencyFactories.set(
|
23 |
|
|
PrefetchDependency,
|
24 |
|
|
normalModuleFactory
|
25 |
|
|
);
|
26 |
|
|
}
|
27 |
|
|
);
|
28 |
|
|
compiler.hooks.make.tapAsync("PrefetchPlugin", (compilation, callback) => {
|
29 |
|
|
compilation.prefetch(
|
30 |
|
|
this.context || compiler.context,
|
31 |
|
|
new PrefetchDependency(this.request),
|
32 |
|
|
callback
|
33 |
|
|
);
|
34 |
|
|
});
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
module.exports = PrefetchPlugin;
|