当前位置:网站首页>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
边栏推荐
- Mysql database backup script
- 47_Opencv中的轮廓查找 cv::findContours()
- Talk about the cloud deployment of local projects created by SAP IRPA studio
- Iptables only allows the specified IP address to access the specified port
- 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
- Mysql database basic operation DQL basic query
- Notification uses full resolution
- Numpy --- basic learning notes
- Eye of depth (VI) -- inverse of matrix (attachment: some ideas of logistic model)
- 分类模型评价标准(performance measure)
猜你喜欢
Xcode Revoke certificate
torch. Numel action
Three. JS introductory learning notes 15: threejs frame animation module
95. (cesium chapter) cesium dynamic monomer-3d building (building)
融云斩获 2022 中国信创数字化办公门户卓越产品奖!
Odoo集成Plausible埋码监控平台
神经网络c语言中的指针是怎么回事
Description of vs common shortcut keys
Logback日志框架第三方jar包 免费获取
Continuous creation depends on it!
随机推荐
47_Opencv中的轮廓查找 cv::findContours()
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
The inevitable trend of the intelligent development of ankerui power grid is that microcomputer protection devices are used in power systems
What are compiled languages and interpreted languages?
一个普通人除了去工厂上班赚钱,还能干什么工作?
MySQL数据库基本操作-DQL-基本查询
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
A JS script can be directly put into the browser to perform operations
121. 买卖股票的最佳时机
安科瑞电网智能化发展的必然趋势电力系统采用微机保护装置是
Application example of infinite list [uigridview]
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
Odoo integrated plausible embedded code monitoring platform
Three. JS introductory learning notes 00: coordinate system, camera (temporarily understood)
Three. JS introductory learning notes 18: how to export JSON files with Blender
Introduction to pyGame games
Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models
Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
AE learning 02: timeline