当前位置:网站首页>The global style caused by sideeffects disappears
The global style caused by sideeffects disappears
2022-04-23 00:12:00 【Buliang_ C】
List of articles
One 、 Problem description
CSS Global style , Style of element , Can't be packaged into , After the code introduced by the style is packaged , It's generating main.js There is no . The packaged code passes eval perform , But the above style code cannot be found .
Two 、 Problem analysis
The original configuration tree shaking When , Didn't pay much attention to details , All the time package.json Middle configuration "sideEffects": false,. The starting point of the configuration at that time was good , When I introduce a module , I won't introduce all the code in the module , Instead, only the part of the code used is introduced . When the introduced module is not used , Automatically use tree shaking Shake it off .
because tree shaking Only static import is supported ,ES Module In the form of ; Without support CommonJS Dynamic introduction of . Because if it is introduced dynamically ,tree shaking It is not certain whether it is necessary or not before introduction .
I happen to use ES Module In the form of CSS style ,import './style/css', The problem is that styles don't load at all , Directly be tree shaking Shake it off , Default current css Module not used . Some people are trapped by themselves , For a long time …
When using CSS Module When ,import style from ‘./style.css’; Sometimes styles are suddenly loaded , I felt confused at that time , Now think about it. , Just below React Inside className Used in the className={ style.btn }, Thus, the global style is loaded . Now it's all figured out .
3、 ... and 、 resolvent
resolvent :1. In fact, we can use require The way , Dynamic introduction css style , To avoid being tree shaking Shake it off .require('./style.css')
2. Yes css Documents don't do tree shaking, stay sideEffect Add an array to ,[ “*.css” ], incorrect css Document carried out tree shaking.[ recommend ]
summary
Pack carefully , Think more
版权声明
本文为[Buliang_ C]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230008119815.html
边栏推荐
- (转)Aspose.words介绍
- Automatic watering system based on 51 single chip microcomputer
- 解决工业缺陷检测小样本问题
- Compared with the traditional anchor based method, fcos is unique
- Dialogue with Yang jiongwei, fast is reflected in seizing the "bonus". In fact, tob company should run slower
- npm 和 npx 查看依赖包版本
- OpenCV中保存不同深度图像的技巧
- (转)Word2016怎么和mathtype兼容
- SAP integrated WMS system solution process for large enterprises
- API接口知识小结
猜你喜欢
随机推荐
90% of test engineers use postman for interface testing
OpenCV中保存不同深度图像的技巧
算法---链表求和(Kotlin)
L1-071 previous life files (20 points)
(转)Aspose.words编程指南之DOM树结构初识,Node类继承关系及说明
L1-074 finish learning C language in two hours (5 points)
倍福EL5101模块获取光栅尺反馈位置并绑定到NC轴配置
100000 developers swarmed into "cool applications" to bet on scenarios
【ACM】78. 子集(返回所有节点的元素,不用设置终止条件)
基于.NetCore开发博客项目 StarBlog - (3) 模型设计
【ACM】51. N 皇后
【ACM】51. Queen n
OJ daily practice -- iterative method for finding square root
Change the pycharm interface to Chinese and switch between Chinese and English
Detailed explanation of kubernetes (VIII) -- resource allocation list of kubernetes
BGP基本配置
(转)Excel 2016 内存或磁盘空间不足无法打开Excel
(转)Aspose.words编程指南之Working with Document
【ACM】90. Subset II (the de duplication problem of the same tree layer first needs to sort the array (use sort))
EL2124模块接线和引脚含义









