As you refactor and modify applications, it's difficult to manage and keep track of files as they become unused. Keeping this "dead" code around adds noise to your application and reduces clarity. Just as ESLint can tell us when variables become unused, Webpack (with the help of the unused-files-webpack-plugin) can tell us when entire files become unused. First, we'll install the plugin with npm and save it as a devDependency. Next, we'll use npm run scripts to build a new command that will run Webpack with the plugin. Finally, we'll learn how to use Webpack environment variables to conditionally add plugins to your Webpack config. By the end of the lesson, you'll have a useful cli command you can run to check for unused modules in your Webpack build

Install:

npm i -D unused-files-webpack-plugin

Update scripts:

"check-unused": "webpack --mode production --env.unused=true --display=errors-only",

Update webpack.config.js:

/* eslint-env node */
const UnusedFilesPlugin = require('unused-files-webpack-plugin').default; module.exports = (env) => {
const config = {
entry: './src/index.js'
}; if (env && env.unused) {
config.plugins = [
new UnusedFilesPlugin({
failOnUnused: true,
patterns: ['src/*.js']
})
]
} return config;
};

最新文章

  1. 精通AngularJS 读书笔记(2)
  2. VQuery选择器
  3. C语言基础--函数
  4. string.Format , object[] args 使用
  5. 关押罪犯(codevs 1069)
  6. POJ 3233 Matrix Power Series (矩阵快速幂+二分求解)
  7. 2.1CUDA-Thread
  8. jQuery Mobile (中)
  9. casio计算器计算统计数据
  10. git 的常用命令
  11. SpringBoot使用Filter过滤器处理是否登录的过滤时,用response.sendRedirect()转发报错
  12. edgedb 内部pg 数据存储的探索 (五) 运行进程列表信息
  13. jQuery的each使用陷阱
  14. 常见模块(三) pickle模块和json模块
  15. 在notepad++中使用正则匹配功能(一-龥!-~) 中文[利刃篇]
  16. Python之路PythonNet,第四篇,网络4
  17. asp.net webform/mvc导出Excel通用代码
  18. Java NIO Overview
  19. SFTP文件下载
  20. 【Java并发编程二】同步容器和并发容器

热门文章

  1. hdu多校6
  2. .net反射详解 原文://http://blog.csdn.net/wenyan07/article/details/27882363
  3. 字符串hash-RK算法讲解二
  4. Container With Most Water(LintCode)
  5. #、##和__VA_ARGS__
  6. Python开发基础-Day14正则表达式和re模块
  7. 【DFS】【打表】Lattice Animals
  8. [Contest20171005]Maze
  9. 【数学期望】hdu5984 Pocky
  10. 【dfs序+AC自动机+树状数组】BZOJ2434-[Noi2011]阿狸的打字机