Movatterモバイル変換


[0]ホーム

URL:


webpack logo
ag grid
ag charts

IgnorePlugin

IgnorePlugin prevents the generation of modules forimport orrequire calls matching the regular expressions or filter functions.

tip

This plugin works with both JavaScript and CSS, allowing you to ignore specific resources in CSS as well.

Using regular expressions

  • resourceRegExp: A RegExp to test the resource against.
  • contextRegExp: (optional) A RegExp to test the context (directory) against.
newwebpack.IgnorePlugin({ resourceRegExp, contextRegExp});

Using filter functions

  • checkResource (resource, context) A Filter function that receivesresource andcontext as arguments, must return boolean.
newwebpack.IgnorePlugin({checkResource(resource){// do something with resourcereturntrue|false;},});

Example of ignoring Moment Locales

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.

8 Contributors

simon04byzykDullReferenceExceptionEugeneHlushkoFadySamirSadekiamakulovchenxsansnitin315

[8]ページ先頭

©2009-2025 Movatter.jp