PyPI: https://pypi.org/project/jsmin/
Github: https://github.com/tikitu/jsmin

安装

pip install jsmin

使用示例

myfile.js

function foo() {
    console.log('hi')
}

1、命令行中使用

$ python -m jsmin myfile.js

function foo(){console.log('hi')}

2、代码中使用

# -*- coding: utf-8 -*-
from jsmin import jsmin

with open('myfile.js') as js_file:
    minified = jsmin(js_file.read())
    print(minified)
    
# function foo(){console.log('hi')}