[Webpack] Detect Unused Code with Webpack and unused-files-webpack-plugin
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;
};
最新文章
- 精通AngularJS 读书笔记(2)
- VQuery选择器
- C语言基础--函数
- string.Format , object[] args 使用
- 关押罪犯(codevs 1069)
- POJ 3233 Matrix Power Series (矩阵快速幂+二分求解)
- 2.1CUDA-Thread
- jQuery Mobile (中)
- casio计算器计算统计数据
- git 的常用命令
- SpringBoot使用Filter过滤器处理是否登录的过滤时,用response.sendRedirect()转发报错
- edgedb 内部pg 数据存储的探索 (五) 运行进程列表信息
- jQuery的each使用陷阱
- 常见模块(三) pickle模块和json模块
- 在notepad++中使用正则匹配功能(一-龥!-~) 中文[利刃篇]
- Python之路PythonNet,第四篇,网络4
- asp.net webform/mvc导出Excel通用代码
- Java NIO Overview
- SFTP文件下载
- 【Java并发编程二】同步容器和并发容器
热门文章
- hdu多校6
- .net反射详解 原文://http://blog.csdn.net/wenyan07/article/details/27882363
- 字符串hash-RK算法讲解二
- Container With Most Water(LintCode)
- #、##和__VA_ARGS__
- Python开发基础-Day14正则表达式和re模块
- 【DFS】【打表】Lattice Animals
- [Contest20171005]Maze
- 【数学期望】hdu5984 Pocky
- 【dfs序+AC自动机+树状数组】BZOJ2434-[Noi2011]阿狸的打字机