Last change
on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const PrefetchDependency = require("./dependencies/PrefetchDependency");
|
---|
| 9 |
|
---|
| 10 | /** @typedef {import("./Compiler")} Compiler */
|
---|
| 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 | * Apply the plugin
|
---|
| 25 | * @param {Compiler} compiler the compiler instance
|
---|
| 26 | * @returns {void}
|
---|
| 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;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.