12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- "use strict";
- const validateOptions = require("schema-utils");
- const schema = require("../schemas/plugins/IgnorePlugin.json");
- class IgnorePlugin {
-
- constructor(options) {
-
- if (arguments.length > 1 || options instanceof RegExp) {
- options = {
- resourceRegExp: arguments[0],
- contextRegExp: arguments[1]
- };
- }
- validateOptions(schema, options, "IgnorePlugin");
- this.options = options;
-
- this.checkIgnore = this.checkIgnore.bind(this);
- }
-
- checkIgnore(result) {
- if (!result) return result;
- if (
- "checkResource" in this.options &&
- this.options.checkResource &&
- this.options.checkResource(result.request, result.context)
- ) {
-
- if ("checkContext" in this.options && this.options.checkContext) {
- if (this.options.checkContext(result.context)) {
- return null;
- }
- } else {
- return null;
- }
- }
- if (
- "resourceRegExp" in this.options &&
- this.options.resourceRegExp &&
- this.options.resourceRegExp.test(result.request)
- ) {
- if ("contextRegExp" in this.options && this.options.contextRegExp) {
-
-
- if (this.options.contextRegExp.test(result.context)) {
- return null;
- }
- } else {
- return null;
- }
- }
- return result;
- }
-
- apply(compiler) {
- compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => {
- nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
- });
- compiler.hooks.contextModuleFactory.tap("IgnorePlugin", cmf => {
- cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
- });
- }
- }
- module.exports = IgnorePlugin;
|