1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const { validate } = require("schema-utils");
|
9 | const schema = require("../schemas/plugins/IgnorePlugin.json");
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | class IgnorePlugin {
|
16 | |
17 |
|
18 |
|
19 | constructor(options) {
|
20 | validate(schema, options, {
|
21 | name: "Ignore Plugin",
|
22 | baseDataPath: "options"
|
23 | });
|
24 | this.options = options;
|
25 |
|
26 |
|
27 | this.checkIgnore = this.checkIgnore.bind(this);
|
28 | }
|
29 |
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | checkIgnore(resolveData) {
|
38 | if (
|
39 | "checkResource" in this.options &&
|
40 | this.options.checkResource &&
|
41 | this.options.checkResource(resolveData.request, resolveData.context)
|
42 | ) {
|
43 | return false;
|
44 | }
|
45 |
|
46 | if (
|
47 | "resourceRegExp" in this.options &&
|
48 | this.options.resourceRegExp &&
|
49 | this.options.resourceRegExp.test(resolveData.request)
|
50 | ) {
|
51 | if ("contextRegExp" in this.options && this.options.contextRegExp) {
|
52 |
|
53 |
|
54 | if (this.options.contextRegExp.test(resolveData.context)) {
|
55 | return false;
|
56 | }
|
57 | } else {
|
58 | return false;
|
59 | }
|
60 | }
|
61 | }
|
62 |
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 | apply(compiler) {
|
69 | compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => {
|
70 | nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
|
71 | });
|
72 | compiler.hooks.contextModuleFactory.tap("IgnorePlugin", cmf => {
|
73 | cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
|
74 | });
|
75 | }
|
76 | }
|
77 |
|
78 | module.exports = IgnorePlugin;
|