1 | ## Webpack Deadcode Plugin
|
2 |
|
3 | Webpack plugin to detect unused files and unused exports in used files
|
4 |
|
5 | [![npm][npm]][npm-url]
|
6 | [![node][node]][node-url]
|
7 | [![deps][deps]][deps-url]
|
8 | [![licenses][licenses]][licenses-url]
|
9 |
|
10 | ### Installation
|
11 |
|
12 | Via npm:
|
13 |
|
14 | ```bash
|
15 | $ npm install webpack-deadcode-plugin --save-dev
|
16 | ```
|
17 |
|
18 | Via yarn:
|
19 |
|
20 | ```bash
|
21 | $ yarn add -D webpack-deadcode-plugin
|
22 | ```
|
23 |
|
24 | ![output](https://i.imgur.com/mowUPx5.png)
|
25 |
|
26 | ### Usage
|
27 |
|
28 | 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:
|
29 |
|
30 |
|
31 | **Webpack 3**
|
32 | ```js
|
33 | const DeadCodePlugin = require('webpack-deadcode-plugin');
|
34 |
|
35 | const webpackConfig = {
|
36 | ...
|
37 | plugins: [
|
38 | new DeadCodePlugin({
|
39 | patterns: [
|
40 | 'src/**/*.(js|jsx|css)',
|
41 | ],
|
42 | exclude: [
|
43 | '**/*.(stories|spec).(js|jsx)',
|
44 | ],
|
45 | })
|
46 | ]
|
47 | }
|
48 | ```
|
49 |
|
50 | **Webpack 4**
|
51 |
|
52 | ```js
|
53 | const DeadCodePlugin = require('webpack-deadcode-plugin');
|
54 |
|
55 | const webpackConfig = {
|
56 | ...
|
57 | optimization: {
|
58 | usedExports: true,
|
59 | },
|
60 | plugins: [
|
61 | new DeadCodePlugin({
|
62 | patterns: [
|
63 | 'src/**/*.(js|jsx|css)',
|
64 | ],
|
65 | exclude: [
|
66 | '**/*.(stories|spec).(js|jsx)',
|
67 | ],
|
68 | })
|
69 | ]
|
70 | }
|
71 |
|
72 | ```
|
73 |
|
74 | ### Configuration
|
75 |
|
76 | ```js
|
77 | new DeadCodePlugin(options)
|
78 | ```
|
79 |
|
80 | #### options.patterns
|
81 |
|
82 | The array of patterns to look for unused files and unused export in used files.
|
83 |
|
84 | + Default: `["**/*.*"]`
|
85 | + Directly pass to [`fast-glob`](https://github.com/mrmlnc/fast-glob)
|
86 |
|
87 | #### options.exclude
|
88 |
|
89 | The array of patterns to not look at.
|
90 |
|
91 | #### options.context
|
92 |
|
93 | Current working directoy for patterns above. If you don't set explicitly, your webpack context will be used.
|
94 |
|
95 |
|
96 | [npm]: https://img.shields.io/npm/v/webpack.svg
|
97 | [npm-url]: https://npmjs.com/package/webpack
|
98 |
|
99 | [node]: https://img.shields.io/node/v/webpack.svg
|
100 | [node-url]: https://nodejs.org
|
101 |
|
102 | [deps]: https://img.shields.io/david/MQuy/webpack-deadcode-plugin.svg
|
103 | [deps-url]: https://david-dm.org/MQuy/webpack-deadcode-plugin
|
104 |
|
105 | [licenses]: https://img.shields.io/github/license/MQuy/webpack-deadcode-plugin.svg
|
106 | [licenses-url]: https://github.com/MQuy/webpack-deadcode-plugin/blob/master/LICENSE
|