[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 ...
随机推荐
- python中,将字符串由utf8转gbk
uni_str = utf8_str.decode('utf-8'); gbk_str = uni_str.encode('gbk');
- Mysql数据库表的类型有哪些
截至目前,MySQL一共向用户提供了包括DBD.HEAP.ISAM.MERGE.MyIASM.InnoDB以及Gemeni这7种Mysql表类型.其中DBD.InnoDB属于事务安全类表,而其他属于事 ...
- 洛谷P1330 封锁阳光大学 [图论,染色]
题目传送门 封锁阳光大学 题目描述 曹是一只爱刷街的老曹,暑假期间,他每天都欢快地在阳光大学的校园里刷街.河蟹看到欢快的曹,感到不爽.河蟹决定封锁阳光大学,不让曹刷街. 阳光大学的校园是一张由N个点构 ...
- PLSQL的注释技巧
概述 这里提供一些注释的技巧,用来模仿Java中的文档注释的功能. 在Eclipse中,鼠标悬浮在类或其成员上,会显示相关的文档注释:在PL/SQL中也有类似的功能,我们需要掌握一些注释技巧,让其可读 ...
- Luogu P2146 软件包管理器(树链剖分+线段树)
题意 给定\(n\)个软件包,每个软件包都有一个依赖软件包,安装一个软件包必须安装他的依赖软件包,卸载一个软件包必须先卸载所有依赖于它的软件包.给定\(m\)此操作,每次一个操作\(install/u ...
- CSS排版常用值指南
高对比度是确保网页阅读无障碍的关键,但也往往会被过分强调. 白底黑子会让打断文本显得过分密集,反而影响可读性. 文字颜色 3b4348 链接颜色 235ea7 衬线字体 font-family: &q ...
- 取得指定Schema下的表
MYSQL中取得指定Schema下所有表定义的SQL语句如下(假设Schema名为demoschema): SHOWTABLES FROM demoschema MSSQLServer中的系统表sys ...
- Python开发基础-Day7-闭包函数和装饰器基础
补充:全局变量声明及局部变量引用 python引用变量的顺序: 当前作用域局部变量->外层作用域变量->当前模块中的全局变量->python内置变量 global关键字用来在函数或其 ...
- 输入输出格式之Python版
# 有多组输入数据,但没有具体的告诉你有多少组,只是让你对应每组输入,应该怎样输出. while True: try: a, b = map(int, raw_input().strip().spli ...
- css总结——position
CSS(Cascading Style Sheet),中文翻译为层叠样式表,是用于控制网页样式并允许将样式信息与网页内容分离的一种标记性语言.在css控制页面中,主要有四种样式:行内样式(style ...