This is an automated email from the ASF dual-hosted git repository.
carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new 55a59c6 Minification method that does a good compression about 30-35%
of CSS reduction (solves apache/royale-compiler#39)
55a59c6 is described below
commit 55a59c62268590e17c7617a7b14d8b562d15fe2b
Author: Carlos Rovira <[email protected]>
AuthorDate: Tue Apr 10 23:00:34 2018 +0200
Minification method that does a good compression about 30-35% of CSS
reduction (solves apache/royale-compiler#39)
---
.../codegen/mxml/royale/MXMLRoyalePublisher.java | 5 ++---
.../driver/js/royale/JSCSSCompilationSession.java | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
index 0335f24..714021e 100644
---
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
+++
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
@@ -765,9 +765,8 @@ public class MXMLRoyalePublisher extends JSGoogPublisher
implements IJSPublisher
if (minify)
{
- //remove \r\n, \n for now this needs more work at this point
- cssString = cssString.replaceAll("\\r\\n|\\n", "");
- writeFile(new File(targetDir, projectName + ".min.css"),
cssString, false);
+ //minify CSS for release
+ writeFile(new File(targetDir, projectName + ".min.css"),
JSCSSCompilationSession.minifyCSSString(cssString), false);
} else {
writeFile(new File(targetDir, projectName + ".css"), cssString,
false);
}
diff --git
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
index f1b2661..fad1da8 100644
---
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
+++
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
@@ -87,6 +87,22 @@ public class JSCSSCompilationSession extends
CSSCompilationSession
walkCSS(css, sb);
return sb.toString();
}
+
+ /**
+ * used to minify the CSS for release mode
+ */
+ public static String minifyCSSString(String cssString)
+ {
+ cssString = cssString.replaceAll("/\\*[\\d\\D]*?\\*/", "");
+ cssString = cssString.replace(";}", "}");
+ cssString = cssString.replaceAll("[a-zA-Z]+#", "#");
+ cssString = cssString.replaceAll("[\\n\\r]+\\s*", "");
+ cssString = cssString.replaceAll("\\s+", " ");
+ cssString = cssString.replaceAll("\\s?([:,;{}])\\s?", "$1");
+ cssString = cssString.replaceAll("([\\s:]0)(px|pt|%|em)", "$1");
+
+ return cssString;
+ }
private String fontFaceToString(CSSFontFace fontFace)
{
--
To stop receiving notification emails like this one, please contact
[email protected].