Created
August 9, 2022 09:50
-
-
Save Tc-001/d348c8493413797352e492f6e41128e6 to your computer and use it in GitHub Desktop.
Quick and dirty html+css+js collapse/minify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const min = (html:string) => html | |
| .replace(/(\n|\s)*(<[^>]*>)(\n|\s)*/g, "$2") //Collapse whitespace around tags | |
| .replace(/(?<=<style[^>]*>[^<]+)(\{|;|:|\r)(\s)+(?=[^<]+<\/style>)/g, "$1") //Collapse css | |
| .replace(/(?<=<script[^>]*>[^<]+)\s*([\{\}\,\;])\s*(?=[^<]+<\/script>)/g, "$1") //Collapse scripts | |
| .replace(/[^\S\r\n]+/g," ") //Remove spaces | |
| .replace(/\n+/g,"\n") //Remove newlines | |
| /* | |
| Will not remove all that can be removed | |
| Focus was more on making sure nothing can break if you use mostly valid syntax | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment