webpack-dedupe-plugin
Module deduplication plugin for webpack.
Internally webpack treats modules from different directories as completely different modules, and in result bundle there will be all these modules as separate entries which leads to duplication and bundle size increase. This module allows to leave only one of these modules based on chosen strategy.
Usage
// webpack.config.js
const { DedupePlugin } = require('@tinkoff/webpack-dedupe-plugin')
module.exports = {
...
plugins: [
new DedupePlugin({
strategy: "equality",
})
]
}
Api
Options
strategy
equality is used by default
"equality"
- uses strict version comparison. Dedupes modules innode_modules
with equal package version that are imported from different sources. E.g. imports fornode_modules/package/index.js
andnode_modules/nested-package/node_modules/package/index.js
are deduped into a singlenode_modules/package/index.js
import whilst without dedupe it will bundle two files as separate modules."semver"
- compares version of packages based on semver. It can dedupe all of the imports with the same major version and any of the minor and patch versions. E.g. next versions will be deduped: from1.14.0
and1.16.2
to1.16.2
, from0.14.1
and0.16.5
to0.16.5
, whilst versions0.0.2
and0.0.5
will be left without deduplication.false
- disable deduplication, by default
ignorePackages
List of regular expressions that specify which modules should not be deduplicated.
showLogs
By default logs are enabled
Output logs about deduplicated paths to the console after build.
onDedupeInfo
Event handler that gets the info about dedupe packages after build, but before the default logs from the plugin are shown