Prevent generation of modules for
require calls matching the following regular expressions:
requestRegExpA RegExp to test the request against.
contextRegExp(optional) A RegExp to test the context (directory) against.
new webpack.IgnorePlugin(requestRegExp, [contextRegExp]);
The following examples demonstrate a few ways this plugin can be used.
requestRegExp parameter passed to
IgnorePlugin is not tested against the resolved file names or absolute module names being imported or required, but rather against the string passed to
import within the source code where the import is taking place. For example, if you're trying to exclude
node_modules/moment/locale/*.js, this won't work:
moment imports with this code:
require('./locale/' + name);
...your first regexp must match that
'./locale/' string. The second
contextRegExp parameter is then used to select specific directories from where the import took place. The following will cause those locale files to be ignored:
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/);
...which means "any require statement matching
'./locale' from any directories ending with
'moment' will be ignored.