当前位置:网站首页>Tragedy caused by deleting the console statement
Tragedy caused by deleting the console statement
2022-07-07 16:20:00 【Bashan queer dialect】
Preface :
although babel-plugin-transform-remove-console It has not been updated for several years , But when packing, remove console The sentence is still relatively time-saving and labor-saving , So it is used in the project , I didn't expect it would be hard
The original question was simple , But sometimes not careful , It may waste a lot of time solving problems , So write a blog , Convenient for others
Quickly quickly your mother call you. , Please detour
1、 Installation and use
install
npm i babel-plugin-transform-remove-console
To configure (babel.config.js)
// Store the plug-ins needed in the project release phase
const productPlugins = []
// If the user is running a package command (npm run build) Inject plug-ins into the array
if (process.env.NODE_ENV === 'production') {
// Release stage
productPlugins.push("transform-remove-console")
}
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
],
plugins: [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
],
...productPlugins
]
}
here , Use npm run build
Command packaging will remove... From the file console sentence , After testing , That's true
2. Delete map file
later , In order to further reduce dist Volume of catalog , It was decided that productionSourceMap Set to false, The purpose is not to generate map The mapping file , This process is apart from the problem
2.1 What is? map file ?
Have a look first , Generated by default dist Catalog
- 4 individual js file ,4 individual map file
- js Catalog total 14M,4 individual map The file takes up 11M
These are a few map What exactly do documents do ?
Its main function is after packaging js Establish a mapping between the file and the source code file before packaging , In this way, although the code before and after packaging looks different , But when an error occurs at runtime , You can still locate the source file where the error occurred
Let's demonstrate
such as , We deliberately App.vue The following codes are included in
methods: {
f1() {
return a + 5
},
},
created() {
this.f1()
},
Under development mode , Running the page , The error information is as follows
Click on the wrong file , You can also directly locate
After the project is packaged ?
After we pack , Running the code , Found a blank article in the console , Not that as long as there is map file , After a mistake , It will not only print errors on the console , Can you still locate the wrong source file ?
2.2 Vanished console
Think about it , When the program reports an error , Who outputs the error message in the console ?
For example, the following mistakes , Tips a is not defined
Obviously , By vue adopt console.error Printed on the console
But let's look at what we see above 4 individual js Document and 4 individual map After the file found that , None of them console sentence , Why? ?
The reason is clear , It is written by developers themselves console Statements and some dependencies introduced by programs console sentence , All be babel-plugin-transform-remove-console Plug in removed
original babel-plugin-transform-remove-console The plug-in can delete all files console sentence ( Isn't that for granted )
2.3 How to solve
Actually , Official documents have long said
therefore , modify babel.config.js Middle configuration , Add exception for deletion , In this way, all the files console.error and console.warn Just keep it
here , You can view the package generated js and map In file , Filled with a large number of the above two statements
After repacking , Run again
It was found that the output was wrong , And prompt which source file the error occurred in
2.4 Cancel map file
Last , You can cancel the generation map The file
vue.config.js in
REPACK , And then run , Still include , But we can't locate the specific source file where the error occurred , But the generated file
go through dist/js Catalog , There is no such thing as map The file , Of course dist The volume of the directory is much smaller
When requested by the client , Will not download map file , So the speed will also increase
3. summary
babel-plugin-transform-remove-console The use of plug-ins is very simple , But if you read your posts carefully , It seems that they are all copied from the same template , Few people mention exclude The function of attributes , If you are a newcomer and encounter problems similar to the above , It may take a lot of time to solve , So write this blog , Convenient for others
边栏推荐
- Odoo集成Plausible埋码监控平台
- What else can an ordinary person do besides working in a factory to make money?
- C4D learning notes 3- animation - animation rendering process case
- Application example of infinite list [uigridview]
- Excessive dependence on subsidies, difficult collection of key customers, and how strong is the potential to reach the dream of "the first share of domestic databases"?
- 删除 console 语句引发的惨案
- torch. Numel action
- Unity的三种单例模式(饿汉,懒汉,MonoBehaviour)
- Enterprise log analysis system elk
- Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
猜你喜欢
What about the pointer in neural network C language
Three. JS introductory learning notes 18: how to export JSON files with Blender
Numpy -- data cleaning
Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
Plate - forme de surveillance par étapes zabbix
Sysom case analysis: where is the missing memory| Dragon lizard Technology
强化实时数据管理,英方软件助力医保平台安全建设
Excessive dependence on subsidies, difficult collection of key customers, and how strong is the potential to reach the dream of "the first share of domestic databases"?
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
随机推荐
L'application à l'échelle de la normalisation mature des produits ai des compagnies maritimes, cimc, leader mondial de l'intelligence artificielle portuaire et maritime / intelligence artificielle des
分步式監控平臺zabbix
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
MySQL中, 如何查询某一天, 某一月, 某一年的数据
laravel post提交数据时显示异常
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
Apache Doris刚“毕业”:为什么应关注这种SQL数据仓库?
统计学习方法——感知机
Performance measure of classification model
模仿企业微信会议室选择
Notification uses full resolution
121. 买卖股票的最佳时机
Bidding announcement: Panjin people's Hospital Panjin hospital database maintenance project
修改配置文件后tidb无法启动
招标公告:福建省农村信用社联合社数据库审计系统采购项目(重新招标)
[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3
Xcode Revoke certificate
Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
平衡二叉树(AVL)