Skip to content

Webpack plugin to detect unused files and unused exports in used files

License

Notifications You must be signed in to change notification settings

huytd/webpack-deadcode-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webpack Deadcode Plugin

Webpack plugin to detect unused files and unused exports in used files

npm node deps licenses

Installation

Via npm:

$ npm install webpack-deadcode-plugin --save-dev

Via yarn:

$ yarn add -D webpack-deadcode-plugin

output

Usage

The plugin will report unused files and unused exports into your terminal but those are not part of your webpack build process, therefore, it will not fail your build (warning you). Simple add into your webpack config as follows:

Webpack 3

const DeadCodePlugin = require('webpack-deadcode-plugin');

const webpackConfig = {
  ...
  plugins: [
    new DeadCodePlugin({
      patterns: [
        'src/**/*.(js|jsx|css)',
      ],
      exclude: [
        '**/*.(stories|spec).(js|jsx)',
      ],
    })
  ]
}

Webpack 4

const DeadCodePlugin = require('webpack-deadcode-plugin');

const webpackConfig = {
  ...
  optimization: {
    usedExports: true,
  },
  plugins: [
    new DeadCodePlugin({
      patterns: [
        'src/**/*.(js|jsx|css)',
      ],
      exclude: [
        '**/*.(stories|spec).(js|jsx)',
      ],
    })
  ]
}

Configuration

new DeadCodePlugin(options)

options.patterns

The array of patterns to look for unused files and unused export in used files.

  • Default: ["**/*.*"]
  • Directly pass to fast-glob

options.exclude

The array of patterns to not look at.

options.context

Current working directoy for patterns above. If you don't set explicitly, your webpack context will be used.

About

Webpack plugin to detect unused files and unused exports in used files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%