Plugins

Webpack has a rich plugin interface. Most of the features within webpack itself use this plugin interface. This makes webpack flexible.

The plugins below are grouped by what they do. Most ship with webpack itself and are used as new webpack.SomePlugin(); the ones whose page lives under a *-webpack-plugin name are separate packages to install first.

Sources and modules

NameDescription
DefinePluginAllow global constants configured at compile time
EnvironmentPluginShorthand for using the DefinePlugin on process.env keys
ProvidePluginUse modules without having to use import/require
IgnorePluginExclude certain modules from bundles
NormalModuleReplacementPluginReplace resource(s) that matches a regexp
ContextReplacementPluginOverride the inferred context of a require expression
ContextExclusionPluginExclude matching contexts so webpack does not generate modules for them
VirtualUrlPluginCreate modules whose content is generated at build time, with no file on disk

Output and assets

NameDescription
BannerPluginAdd a banner to the top of each generated chunk
CopyPluginCopy files and directories into the output directory
CopyWebpackPluginSuperseded by the built-in CopyPlugin
ManifestPluginGenerate an asset manifest mapping source filenames to emitted output files
CompressionWebpackPluginPrepare compressed versions of assets to serve them with Content-Encoding
ChunksWebpackPluginCreate HTML files with entrypoints and chunks relations to serve your bundles
SvgChunkWebpackPluginGenerate SVG sprites optimized by SVGO based on your entry point dependencies

Chunks and optimization

NameDescription
SplitChunksPluginExtract shared and vendor code into separate chunks — configured through optimization.splitChunks
ModuleConcatenationPluginScope hoisting — on by default in production via optimization.concatenateModules
MergeDuplicateChunksPluginMerge chunks that contain the same modules
LimitChunkCountPluginLimit the maximum number of chunks by merging them
MinChunkSizePluginKeep chunk size above the specified limit
MinimizerPluginUses Terser (or other) to minify the JS/CSS/HTML/JSON/etc in your project
HashedModuleIdsPluginHash-based module IDs — use optimization.moduleIds: 'deterministic' instead, which is the production default
NoEmitOnErrorsPluginSkip the emitting phase when there are compilation errors
AutomaticPrefetchPluginResolve all modules from the previous compilation upfront to speed up watch rebuilds
PrefetchPluginResolve and build a module ahead of its first import to shorten the critical build path
DllPluginSplit bundles into a pre-built vendor bundle — largely replaced by the filesystem cache

Module Federation

NameDescription
ModuleFederationPluginShare modules between independently built applications at runtime

Development and diagnostics

NameDescription
HotModuleReplacementPluginEnable Hot Module Replacement (HMR)
SourceMapDevToolPluginEnables a more fine grained control of source maps
EvalSourceMapDevToolPluginEnables a more fine grained control of eval source maps
ProgressPluginReport compilation progress
ProfilingPluginRecord plugin execution timings to a Chrome profile file
WatchIgnorePluginIgnore matching paths in watch mode so they do not trigger rebuilds
DiagnosticsWebpackPluginRun linters and other diagnostic tools over your sources during the build

For more third-party plugins, see the list from awesome-webpack.

Edit this page·

10 Contributors

simon04gonzoyumorouzbeh84aretecodeeko3alpharefactorizedbyzykEugeneHlushkosnitin315chenxsan