[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;
};
[Webpack] Detect Unused Code with Webpack and unused-files-webpack-plugin的更多相关文章
- [Webpack 2] Add Code Coverage to tests in a Webpack project
How much of your code runs during unit testing is an extremely valuable metric to track. Utilizing c ...
- webpack打包 The 'mode' option has not been set, webpack will fallback to
webpack 打包报错 The 'mode' option has not been set, webpack will fallback to 'production' for,Module no ...
- Webpack实战(五):轻松读懂Webpack如何分离样式文件
在上一篇文章中我给大家分享了预处理器(loader),里面讲到了style-loader 和css-loader,有关样式引入的问题,但是上面的样式文件只是引入到style标签里面,并不是我想要的样式 ...
- 在webpack中使用Code Splitting--代码分割来实现vue中的懒加载
当Vue应用程序越来越大,使用Webpack的代码分割来懒加载组件,路由或者Vuex模块, 只有在需要时候才加载代码. 我们可以在Vue应用程序中在三个不同层级应用懒加载和代码分割: 组件,也称为异步 ...
- webpack优化之code splitting
作为当前风头正盛的打包工具,webpack风靡前端界.确实作为引领了一个时代的打包工具,很多方面都带来了颠覆性的改进,让我们更加的感受到自动化的快感.不过最为大家诟病的一点就是用起来太难了. 要想愉快 ...
- [Tools] Support VS Code Navigation and Autocomplete Based on Webpack Aliases with jsconfig.json
It's common to setup Webpack aliases to make imports much more convenient, but then you lose the abi ...
- webpack学习之—— Code Spliting(代码分离)
代码分离特性能够把代码分离到不同的 bundle 中,然后可以按需加载或并行加载这些文件.代码分离可以用于获取更小的 bundle,以及控制资源加载优先级,如果使用合理,会极大影响加载时间. 有三种常 ...
- [Webpack] Externalize Dependencies to be Loaded via CDN with webpack
We can separate our custom application code from the common libraries we leverage, such as React and ...
- webpack学习(二):先写几个webpack基础demo
一.先写一个简单demo1 1-1安装好webpack后创建这样一个目录: 1-2:向src各文件和dist/index.html文件写入内容: <!DOCTYPE html> <h ...
随机推荐
- CentOS7安装和配置samba
(1)samba简介 CIFS:通用的internet文件系统,windows和unix系统之间共享文件的一种协议;客户端主要是windows:支持多节点同时挂载以及并发写入 (2)samba主配置文 ...
- spark启动问题,发现任务都是在localhost下面运行的,原来启动spark-shell的时候需要带主节点的参数
在Spark 集群上运行一个应用,只需通过master的 spark://IP:PORT 链接传递到SparkContext构造器 在集群上运行交互式的Spark 命令, 运行如下命令: MASTER ...
- ExtJs之组件(window)
Ext.create('Ext.window.Window',{ title:'', width:400, height:300, constrain:true,//限制窗口不 ...
- 洛谷——P2388 阶乘之乘
P2388 阶乘之乘 题目背景 不告诉你…… 题目描述 求出1!*2!*3!*4!*……*n!的末尾有几个零 输入输出格式 输入格式: n(n<=10^8) 输出格式: 有几个零 输入输出样例 ...
- 初雪-Diary?
who care ------------2018 11 6-------------- 终于AK一场啦 ------------2018 10 18-------------- 嗯....今天T2多 ...
- 2017 icpc 南宁网络赛
2000年台湾大专题...英语阅读输入输出专场..我只能说很强势.. M. Frequent Subsets Problem The frequent subset problem is define ...
- Luogu P3362 Cool loves shaxian 生成函数
题意: 定义f(i)=∑ k∣i k^d(i≤n),给出q个询问,每个询问询问区间[l,r]的f(i)的和. n<=1e7 d<=1e18 q<=5e4 可以发现f(i)是个积性函数 ...
- [UOJ217]奇怪的线段树
如果一个节点是$0$但它子树内有$1$那么无解,否则我们只需把那些是$1$但子树内没有其他$1$的节点(这些区间是被定位的区间)都访问一遍即可 根据ZKW线段树定位区间的过程,可以发现一段(从左到右) ...
- 【状压dp】CDOJ1608 暑假集训
裸的状压的话,很显然……但有一个强大的优化. 就是在枚举决策的时候,固定第一个空位置.可以证明,这样状态数没有减少,但是降低了很多重复访问. 因为你在枚举的时候,总是可以划分为包含第一个空位置的3个位 ...
- Vue视图下
3 Vue视图 3.5 样式绑定 class绑定 <p :class='对象'> <p :class="数组"> <p :class="{类 ...