Skip to content

fengzilong/duplicate-dependencies-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

duplicate-dependencies-webpack-plugin

npm version npm downloads actions status

A webpack plugin to find all duplicated dependencies in your bundle

screenshot

Installation

For yarn users

yarn add duplicate-dependencies-webpack-plugin --dev

For npm users

npm i duplicate-dependencies-webpack-plugin -D

Basic Usage

webpack.config.js

const { DuplicateReporterPlugin } = require( 'duplicate-dependencies-webpack-plugin' )

module.exports = {
  plugins: {
    new DuplicateReporterPlugin()
  }
}

Advanced Usage

This plugin is designed to be more flexible

So you may want to use it together with a reporter plugin

Internally this plugin expose a hook called result

webpack.config.js

const DuplicatePlugin = require( 'duplicate-dependencies-webpack-plugin' )

const ID = 'duplicates-reporter'
class DuplicatesReporterPlugin {
  apply( compiler ) {
    compiler.hooks.compilation.tap( ID, compilation => {
      DuplicatePlugin.getHooks( compilation ).result
        .tap( ID, duplicates => {
          // here you get the `duplicates` data
          // do whatever you want with this
          useCustomPrettyReporter( duplicates )
        } )
    } )
  }
}

module.exports = {
  plugins: {
    new DuplicatePlugin(),
    new DuplicatesReporterPlugin()
  }
}

duplicates looks like:

{
  'package_name': [
    {
      name: 'package_name',
      version: '4.2.2',
      root: 'absolute_path_to_package_root',
      issuer: 'absolute_path_to_issuer', // the file issue the request
      files: [Array], // files in this package which are included in your bundle
      bytes: 4000 // bytes contributed by this packages
    },
    // ...more versions
  ]
}

License

MIT

About

A webpack plugin to check all duplicated dependencies in your bundle

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published