Pyhton压缩JS代码
作者:小教学发布时间:2023-09-25分类:程序开发学习浏览:102
导读:文章目录1.安装依赖2.目录结构3.代码4.执行结果1.安装依赖pipinstalljsmin2.目录结构3.代码importjsm...
文章目录
- 1.安装依赖
- 2.目录结构
- 3.代码
- 4.执行结果
1.安装依赖
pip install jsmin
2.目录结构
3.代码
import jsmin
def run(src_path, tgt_path):
with open(src_path, "r", encoding='utf-8') as input_file:
with open(tgt_path, "w", encoding='utf-8') as output_file:
output_file.write(jsmin.jsmin(input_file.read()))
if __name__ == '__main__':
# 压缩哪个js
src_path = "./src/ExLibris列表页.js"
# 压缩后放哪
tgt_path = "./tgt/ExLibris列表页.js"
# 执行
run(src_path, tgt_path)
4.执行结果
- 程序开发学习排行
- 最近发表