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