当前位置:网站首页>nodejs 时钟案例(fs模块),重复使用fs.writeFile方法,旧内容会被覆盖
nodejs 时钟案例(fs模块),重复使用fs.writeFile方法,旧内容会被覆盖
2022-08-10 02:17:00 【差不少】
时钟案例



步骤2:
步骤三:自定义resolveCSS方法
注意:css匹配style标签.exec()匹配css样式
步骤4:自定义resolveJS方法
步骤5:自定义resolveHYML方法来处理html代码(不包含css样式和js脚本)
注意:newHTML就是处理完的(只包含结构,不包含样式和脚本)
注意:最后被修改的html文件中的css和js都会以外链的形式引入


注意:思路整理
用fs变量来读写文件
用path变量来处理路径regStyle来匹配style标签regScript来匹配script标签
读取 素材 目录下的index.html文件,读取成功后,用对应的三个方法(resolveCSS,resolveJS,resolveHTMl)来分别拆解出css,js,html三个文件
reovleCSS中通过正则的exec方法来提取css代码,然后把style标签通过replace方法去除(替换成空),然后把代码写入index.css文件中
reovleJS中通过正则的exec方法来提取js代码,然后把script标签通过replace方法去除(替换成空),然后把代码写入index.js文件中
resolveHTML通过replace方法,把css的代码和js代码替换成对应的link外链,最后写入index.html文件中
完整代码:




注意:时钟案例中的两个注意点
注意:没有对应路径(文件夹),在其中执行文件会报错
注意:同一文件重复使用fs.writeFile方法,旧内容会被覆盖
边栏推荐
- P1564 Worship
- HackTheBox——Beep
- 微生物是如何影响身体健康的
- [Red Team] ATT&CK - Auto Start - Registry Run Key, Startup Folder
- Algorithm and voice dialogue direction interview question bank
- [Kali Security Penetration Testing Practice Course] Chapter 7 Privilege Escalation
- Example 045: Summation
- 2022强网杯 Quals Reverse 部分writeup
- 2022.8.8 Exam area link (district) questions
- 2022.8.9 Exam Cube Sum--1100 Question Solutions
猜你喜欢

微生物是如何影响身体健康的

《GB39707-2020》PDF下载

推荐几款好用的MySQL开源客户端,建议收藏

Arcgis进阶篇(1)——安装Arcgis Enterprise,创建sde库

是什么让训练综合分类网络艰苦?

Example 045: Summation

liunx PS1 settings
![[Kali Security Penetration Testing Practice Course] Chapter 9 Wireless Network Penetration](/img/7d/c621680ac73e2987f023a2e98e01df.png)
[Kali Security Penetration Testing Practice Course] Chapter 9 Wireless Network Penetration

【图像分类】2022-ResMLP

Database management tool: dynamic read-write separation
随机推荐
QT模态对话框及非模态对话框学习
SQLserver加个判断
What is a Cross-Site Request Forgery (CSRF) attack?How to defend?
量化交易策略介绍及应用市值中性化选股
2022 Top Net Cup Quals Reverse Partial writeup
HRnet
【8.8】代码源 - 【不降子数组游戏】【最长上升子序列计数(Bonus)】【子串(数据加强版)】
Database management tool: dynamic read-write separation
剑指offer专项突击版第25天
T5: Text-to-Text Transfer Transformer
【Image Classification】2022-ConvMixer ICLR
liunx PS1 settings
MMDetection框架的anchor_generators.py解析
The 25th day of the special assault version of the sword offer
ECCV 2022 Oral | CCPL: 一种通用的关联性保留损失函数实现通用风格迁移
MySQL: Introduction to Logging System | Error Log | Query Log | Binary Log: Bin-log Data Recovery Practice | Slow Log Query
Web mining traceability?Browser browsing history viewing tool Browsinghistoryview
【Image Classification】2022-ResMLP
781. 森林中的兔子
2022.8.9 Remainder of Exam Balance--1000 Question Solutions