from jsmin import jsmin with open('myfile.js') as js_file: minified = jsmin(js_file.read())
You can run it as a commandline tool also:
python -m jsmin myfile.js
NB: jsmin makes no attempt to be compatible with ECMAScript 6 / ES.next / Harmony. The current maintainer does not intend to add ES6-compatibility. If you would like to take over maintenance and update jsmin for ES6, please contact Tikitu de Jager. Pull requests are also welcome, of course, but my time to review them is somewhat limited these days.
If you’re using jsmin on ES6 code, though, you might find the quote_chars parameter useful:
from jsmin import jsmin with open('myfile.js') as js_file: minified = jsmin(js_file.read(), quote_chars="'\"`")
If possible, please make separate pull requests for tests and for code: tests will be added to the latest-release branch while code will go to master.
Unless you request otherwise, your Github identity will be added to the contributor’s list below; if you prefer a different name feel free to add it in your pull request instead. (If you prefer not to be mentioned you’ll have to let the maintainer know somehow.)
Both branches are tested with Travis: https://travis-ci.org/tikitu/jsmin
The latest-release branch (the version on PyPI plus any new tests) is tested against CPython 2.6, 2.7, 3.2, and 3.3. Currently:
If that branch is failing that means there’s a new test that fails on the latest released version on pypi, with no fix yet released.
The master branch (development version, might be ahead of latest released version) is tested against CPython 2.6, 2.7, 3.2, and 3.3. Currently:
If master is failing don’t use it, but as long as latest-release is passing the pypi release should be ok.
Merge #13: Preserve “loud comments” starting with /*!
These are commonly used for copyright notices, and are preserved by various other minifiers (e.g. YUI Compressor).