Package: web-minify
About web-minify (version 1.1.2-test-development)web-minifyis the all-in-one just-works-out-of-the-box does-what-you-want highly-opinionated web minifier™web-minify isavailable on gitlab.Goals of this tool:NOTE: We have not reached all these goals yet, please see next sections.GoalStatusAll-in-one compressor/obfuscator/minifier/cruncher for most of the common static web formatsSeelist of supported formats.Installable via PyPi on platforms supported by Python 3+✅No dependencies on large non-python tool such as nodejs✅Support for images formats such as.pngand.jpeg✅Support for vector graphics formats such as.svg✅Support for style sheet formats such as .css and [.sass](https://en.wikipedia.org/wiki/Sass_(stylesheet_language)✅Support for script formats such as .js✅Support for template formats such as .jinja✅Support for markup formats such as .html✅Handle intertwined formats such as JS and CSS inside HTML❌Does what you hoped by default (i.e. highly opinionated)✅Can be tweaked to do what you didn't want (i.e. flexible)✅Small and dependency free (i.e. implemented in pure python if possible)Only tested/used on Linux. There is hope for OSX/BSD/Posix but YMMV on Windows.Available as library as well as command-line tool✅Easily extensible; adding another backend can be done by writing one function✅Cross platform, supports many Python 3.x versionsOnly tested on Python 3.7Getting startedweb-minifycan be used and hacked on in a myriad of different ways.Use web-minify as a module from your codeweb-minify isavailable in PyPI.# Install web-minify into your current Python environmentpipinstallweb-minifyNow you can access it's features from your code:importweb_minifysettings={"input":"my_originals_dir/","output":"my_processed_dir/",}# Instanciate processor with settings we want to usep=web_minify.processor.Processor(settings)# Process files as per settings (this is equivalent to the commandline mode)p.process_file()# Process a list of files relative to input, and output them depending on settingsp.process_files_list(["input_file.svg","input_file.html"])# Process a single file (disregard input/output from settingsp.process_file("some_input_file.svg","some_output_file.svg")Use web-minify as a command line toolweb-minify isavailable in PyPI.# Install web-minify into your current Python environmentpipinstallweb-minify# Run the web-minify cli tool with help argument to see detailed usageweb-minify--helpThe output looks like this:$./web-minify.py--help

usage:web-minify.py[-h][--version][--mode{Mode.minify,Mode.beautify}][--formatFORMAT][--overwrite][--on-change][--verbose][--quiet][--dry-run][--copy][--force][--diff][--no-size-checks][--size-maxNUM][--size-minNUM][--nprocNUM][--gzip][--disable-type-svg][--disable-type-sql][--disable-type-json][--disable-type-css][--disable-type-png][--disable-type-sass][--disable-type-html][--disable-type-jinja][--disable-type-js][--disable-type-jpeg][--disable-extension-svg][--disable-extension-jinja2][--disable-extension-template][--disable-extension-sql][--disable-extension-pgsql][--disable-extension-jpg][--disable-extension-css][--disable-extension-json][--disable-extension-htm][--disable-extension-png][--disable-extension-tpl][--disable-extension-sass][--disable-extension-html][--disable-extension-scss][--disable-extension-j2][--disable-extension-jinja][--disable-extension-js][--disable-extension-jpeg][--outputOUTPUT][--sort][--comments][--timestamp][--wrap][--set-precisionNUM][--set-c-precisionNUM][--disable-simplify-colors][--disable-style-to-xml][--disable-group-collapsing][--create-groups][--keep-editor-data][--keep-unreferenced-defs][--renderer-workaround][--no-renderer-workaround][--strip-xml-prolog][--remove-titles][--remove-descriptions][--remove-metadata][--remove-descriptive-elements][--enable-comment-stripping][--disable-embed-rasters][--enable-viewboxing][--indentTYPE][--nindentNUM][--no-line-breaks][--strip-xml-space][--enable-id-stripping][--shorten-ids][--shorten-ids-prefixPREFIX][--protect-ids-noninkscape][--protect-ids-listLIST][--protect-ids-prefixPREFIX][--error-on-flowtext]input

optionalarguments:-h,--helpshowthishelpmessageandexitgeneral:Generaloptionsforthisprogram--versionshowprogram's version number and exit--mode {Mode.minify,Mode.beautify}Select mode of operation. Minify will prepare filesfor deployment, beautify will prepare files fordevelopment.--format FORMAT       Format string used to generate any output filename.(Dangerous!!)--overwrite           Allow overwrite of existing destination files in-place. Default is skip and warn. (Dangerous!!)--on-change           Allow overwrite files only on source changed (detectedby modify time).--verbose             Show more output during processing.--quiet               Show no output during processing.--dry-run             Never touch files, only log what would have been done(for debugging purposes)--copy                Just copy files verbatime without processing them.--force               Overwrite even if destination exists and is newer.(Dangerous!!)--diff                Log diff output for every file processed (warning:will be slow and output a lot of log).--no-size-checks      Disable size sanity checks (detects and prevents run-away processors generating huge amounts of data--size-max NUM        Set maximum size of files to process in bytes.--size-min NUM        Set minimum size of files to process in bytes.--nproc NUM           Set number of cores for multiprocessing (default isnumber of cores available which is 24 on this machine)--gzip                Create a GZIP compressed version of every non binaryfile processed with .gz suffix added.--disable-type-svg    Copy svg files verbatim instead of processing them forgiven handler type--disable-type-sql    Copy sql files verbatim instead of processing them forgiven handler type--disable-type-json   Copy json files verbatim instead of processing themfor given handler type--disable-type-css    Copy css files verbatim instead of processing them forgiven handler type--disable-type-png    Copy png files verbatim instead of processing them forgiven handler type--disable-type-sass   Copy sass files verbatim instead of processing themfor given handler type--disable-type-html   Copy html files verbatim instead of processing themfor given handler type--disable-type-jinja  Copy jinja files verbatim instead of processing themfor given handler type--disable-type-js     Copy js files verbatim instead of processing them forgiven handler type--disable-type-jpeg   Copy jpeg files verbatim instead of processing themfor given handler type--disable-extension-svgCopy svg files verbatim instead of processing them forgiven filename extension--disable-extension-jinja2Copy jinja2 files verbatim instead of processing themfor given filename extension--disable-extension-templateCopy template files verbatim instead of processingthem for given filename extension--disable-extension-sqlCopy sql files verbatim instead of processing them forgiven filename extension--disable-extension-pgsqlCopy pgsql files verbatim instead of processing themfor given filename extension--disable-extension-jpgCopy jpg files verbatim instead of processing them forgiven filename extension--disable-extension-cssCopy css files verbatim instead of processing them forgiven filename extension--disable-extension-jsonCopy json files verbatim instead of processing themfor given filename extension--disable-extension-htmCopy htm files verbatim instead of processing them forgiven filename extension--disable-extension-pngCopy png files verbatim instead of processing them forgiven filename extension--disable-extension-tplCopy tpl files verbatim instead of processing them forgiven filename extension--disable-extension-sassCopy sass files verbatim instead of processing themfor given filename extension--disable-extension-htmlCopy html files verbatim instead of processing themfor given filename extension--disable-extension-scssCopy scss files verbatim instead of processing themfor given filename extension--disable-extension-j2Copy j2 files verbatim instead of processing them forgiven filename extension--disable-extension-jinjaCopy jinja files verbatim instead of processing themfor given filename extension--disable-extension-jsCopy js files verbatim instead of processing them forgiven filename extension--disable-extension-jpegCopy jpeg files verbatim instead of processing themfor given filename extension--output OUTPUT       Path to local output (file or folder).input                 Path to local input (file or folder).common:Options common to many formats--sort                Alphabetically sort CSS Properties (CSS).--comments            Keep comments (CSS/HTML).--timestamp           Add a timestamp in output files (CSS/HTML/SVG).--wrap                Wrap output to ~80 chars per line (CSS).svg optimization:Optimization options that are only available for SVG--set-precision NUM   set number of significant digits (default: 5)--set-c-precision NUMset number of significant digits for control points(default: same as '--set-precision')--disable-simplify-colorswon'tconvertcolorsto#RRGGBB format--disable-style-to-xmlwon't convert styles into XML attributes--disable-group-collapsingwon'tcollapse<g>elements--create-groupscreate<g>elementsforrunsofelementswithidenticalattributes--keep-editor-datawon't remove Inkscape, Sodipodi, Adobe Illustrator orSketch elements and attributes--keep-unreferenced-defswon'tremoveelementswithinthedefscontainerthatareunreferenced--renderer-workaroundworkaroundvariousrendererbugs(currentlyonlylibrsvg)(default)--no-renderer-workarounddonotworkaroundvariousrendererbugs(currentlyonlylibrsvg)svgdocument:DocumentoptionsthatareonlyavailableforSVG--strip-xml-prologwon't output the XML prolog (<?xml ?>)--remove-titles       remove <title> elements--remove-descriptionsremove <desc> elements--remove-metadata     remove <metadata> elements (which may contain licenseor author information etc.)--remove-descriptive-elementsremove <title>, <desc> and <metadata> elements--enable-comment-strippingremove all comments (<!-- -->)--disable-embed-rasterswon'tembedrastersasbase64-encodeddata--enable-viewboxingchangesdocumentwidth/heightto100pct/100pctandcreatesviewboxcoordinates

svgoutputformatting:OutputformattingoptionsthatareonlyavailableforSVG--indentTYPEindentationoftheoutput:none,space,tab(default:space)--nindentNUMdepthoftheindentation,i.e.numberofspaces/tabs:(default:1)--no-line-breaksdonotcreatelinebreaksinoutput(alsodisablesindentation;mightbeoverriddenbyxml:space="preserve")--strip-xml-spacestripthexml:space="preserve"attributefromtherootSVGelement

svgidattributes:IDattributeoptionsthatareonlyavailableforSVG--enable-id-strippingremoveallunreferencedIDs--shorten-idsshortenallIDstotheleastnumberofletterspossible--shorten-ids-prefixPREFIXaddcustomprefixtoshortenedIDs--protect-ids-noninkscapedon't remove IDs not ending with a digit--protect-ids-list LISTdon'tremoveIDsgiveninthiscomma-separatedlist--protect-ids-prefixPREFIXdon't remove IDs starting with the given prefixsvg compatability checks:Compatibility check options that are only available for SVG--error-on-flowtext   exit with error if the input SVG uses non-standardflowing text (only warn by default)---------------------------------------------------------__             _      _ ____    _____ / /  ______ _  (_)__  (_) _/_ __| |/|/ / -_) _ \/___/  '\//_\//_////|__,__/\__/_.__//_/_/_/_/_//_/_/_/\_,//___/v1.1.2ProcessallCSS/SASS/HTML/JS/SVG/PNG/JPEGfoundatinput,eitherinsinglefileorrecursivelythroughadirectory.Willoutputinplace,tospecifiedfileorfolderdependingonwhatoutputwasspecified.Willapplytransformationtoeachfileaccordingtoselectedmode:Mode=minify(foroptimizingproduction):+Compile(SASS->CSS)+Stripwhitespace+Stripcomments+Stripmetadata+Increasecompressionratio(PNG,JPEG)+Sort(CSS)+Addtimestamp(CSS,HTML)+Obfuscate(CSS,JS)+HashMode=beautify(foraidingdevelopment):+lint(JS,HTML)+normalizeformat(JS,HTML)Providessomeoptionsforprocessing:+Processfilesin-place+Processfilesrenamingtonewform+Compressresultsto.gz(allnon-binaryfiles)Availablevariablesinformatstringare:+{EXT}+{HASH}+{PATH}+{BASE}Developing web-minifyweb-minify isavailable on gitlab.web-minify welcomes PRs!If you want to contribute we welcome your code contriburtions! We are proud of the fact that this project is a true meritocracy.Example: extending web-minify to support additional formats is done by a very simple interface:Put a module underweb-minify/web_minify/handlers/your_format. This can either be a module folder or python module source file. Seecss/orhtml.pyfor example implementations.Include the new function in__all__inweb-minify/web_minify/handlers/__init__.pyRegister the new function inself.processor_mapinweb-minify/web_minify/processor.pyEasy as 🥧!Supported formatsAlready supported Formats:FormatminifybeautifyTests*.html, *htm, *.tplHypertext Markup Language✅✅❌*.cssCascading Style Sheets✅❌❌*.jsJavaScript✅✝✅❌*.jsonJavaScript Object Notation✅✅❌*.sassSyntactically Awesome Style Sheets✅❌❌*.scssSyntactically Awesome Style Sheets (modern syntax)✅❌❌*.pngPortable Network Graphics✅❌❌*.jpg, *.jpegJoint Photographic Experts Group✅❌❌*.svgScalable Vector Graphics✅❌❌*.sqlStructured Query Language❌✅❌*.your_fileweb-minify is made to beextensible✅✝✝✅✝✝✅✝✝✝Buggy for modern syntax features✝✝Submit your PR!LicenseComplete license is in the fileLICENSEin the root of the git repo.GNU GPL and GNU LGPL or MIT.
This work is free software: You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This work is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; Without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this work.Other Notable FeaturesSupports recursive scanning of directoriesSupports spitting out .gz versions of files to speed up serving of static filesSupports some controls over each format's processingSupports change detection and watch modeMade to be somewhatextensibleKnown Limitations and Problems:Compression of modern .js haves some bugs. We welcome PRs!Some of the usage patterns of the command line tool are not implemented yet. We welcome PRs!Codebase has ZERO tests. We welcome PRs!