File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,8 +32,12 @@ export default (options = {}) => {
3232
3333 /* minify css */
3434 const minifyCSS = ( css ) => {
35- /* Step 1: Remove comments but preserve quoted strings */
36- return css . replace ( / ( " ( [ ^ " \\ ] | \\ .) * " | ' ( [ ^ ' \\ ] | \\ .) * ' ) | \/ \* [ ^ ] * ?\* \/ / g, ( _ , quoted ) => quoted || "" )
35+ const functions = [ ] ;
36+
37+ /* collect function expressions and insert placeholders */
38+ return css . replace ( / \b ( c a l c | m i n | m a x | c l a m p ) \( ( [ ^ ( ) ] * ( \( [ ^ ( ) ] * \) ) * [ ^ ( ) ] * ) \) / g, ( match ) => { functions . push ( match ) ; return `___F${ functions . length - 1 } ___` ; } )
39+ /* Step 1: Remove comments but preserve quoted strings */
40+ . replace ( / ( " ( [ ^ " \\ ] | \\ .) * " | ' ( [ ^ ' \\ ] | \\ .) * ' ) | \/ \* [ ^ ] * ?\* \/ / g, ( _ , quoted ) => quoted || "" )
3741 /* Step 2: Remove spaces around ; and } — keep the closing brace */
3842 . replace ( / \s * ; \s * ( } ) / g, ";$1" )
3943 /* Step 3: Remove spaces around meta characters and operators */
@@ -51,7 +55,9 @@ export default (options = {}) => {
5155 /* Step 9: Collapse multiple spaces into one */
5256 . replace ( / ( \s ) \s + / g, "$1" )
5357 /* Step 10: Replace newlines characters with a space. */
54- . replace ( / \n + / g, " " ) ;
58+ . replace ( / \n + / g, " " )
59+ /* Step 11: Restore all function expressions */
60+ . replace ( / _ _ _ F ( \d + ) _ _ _ / g, ( _ , index ) => functions [ index ] ) ;
5561 } ;
5662
5763 return {
You can’t perform that action at this time.
0 commit comments