npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tfboys/webpack-deadcode-plugin

v1.1.4

Published

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

Downloads

79

Readme

Webpack Deadcode Plugin

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

npm node deps licenses

Installation

Via npm:

$ npm install @tfboys/webpack-deadcode-plugin --save-dev

Via yarn:

$ yarn add -D @tfboys/webpack-deadcode-plugin

output

New Feature

This plugin supports delete unused files and output path of unused files to a json file, then you can easily exclude files you want to ingore.

prompt

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:

✍️ If you use babel-loader, you have to set modules: false to make it works

# in .babelrc
{
  "presets": [
    ["env", { modules: false }]
  ]
}

# or in webpack.config.js -> module/rules
{
  loader: 'babel-loader',
  options: {
    presets: [
      ['env', { modules: false }
    ]
  }
}

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)',
      ],
    })
  ]
}

Using non-existent css class names

To detect using non-existent class names in your codebase, you have to use es6-css-loader instead of style-loader/mini-css-extract-plugin. They are quite similiar in term of api except es6-css-loader supports to detect non-existent css class names.

non-existent css class names

You can check samples folder, how to to config webpack-deadcode-plugin and es6-css-loader.

Typescript

Using with typescript loader (ts-loader, awesome-typescript-loader), if you enable transpileOnly/happyPackMode, output might be not correct due to this issue. In case of incorrect output, the workaround solution is disabling transpileOnly, it will slow down webpack compiling time.

✍ Under some circumstances and production mode, if your output displays incorrect unused files, we encourage switching to awesome-typescript-loader.

Configuration

new DeadCodePlugin(options);

options.patterns (default: ["**/*.*"])

The array of patterns to look for unused files and unused export in used files. Directly pass to fast-glob

options.exclude (default: [])

The array of patterns to not look at.

options.outputFile

The path of file which contains unused files' path

options.context

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

options.failOnHint (default: false)

Deadcode does not interrupt the compilation by default. If you want to cancel the compilation, set it true, it throws a fatal error and stops the compilation.

options.detectUnusedFiles (default: true)

Whether to run unused files detection or not.

options.detectUnusedExport (default: true)

Whether to run unsed export detection or not.