IgnorePlugin prevents the generation of modules forimport orrequire calls matching the regular expressions or filter functions.
This plugin works with both JavaScript and CSS, allowing you to ignore specific resources in CSS as well.
resourceRegExp: A RegExp to test the resource against.contextRegExp: (optional) A RegExp to test the context (directory) against.newwebpack.IgnorePlugin({ resourceRegExp, contextRegExp});checkResource (resource, context) A Filter function that receivesresource andcontext as arguments, must return boolean.newwebpack.IgnorePlugin({checkResource(resource){// do something with resourcereturntrue|false;},});As ofmoment 2.18, all locales are bundled together with the core library (seethis GitHub issue).
TheresourceRegExp parameter passed toIgnorePlugin is not tested against the resolved file names or absolute module names being imported or required, but rather against thestring passed torequire orimportwithin the source code where the import is taking place. For example, if you're trying to excludenode_modules/moment/locale/*.js, this won't work:
-new webpack.IgnorePlugin({ resourceRegExp: /moment\/locale\// });Rather, becausemoment imports with this code:
require('./locale/'+ name);...your first regexp must match that'./locale/' string. The secondcontextRegExp parameter is then used to select specific directories from where the import took place. The following will cause those locale files to be ignored:
newwebpack.IgnorePlugin({ resourceRegExp:/^\.\/locale$/, contextRegExp:/moment$/,});...which means "any require statement matching'./locale' from any directories ending with'moment' will be ignored.