How to use a different minification library for AEM client libraries than the default YUI Compressor library?

Environment

AEM 6.2, 6.3 and later versions

Steps

In AEM6.2 and later versions, you can set properties on cq:ClientLibraryFolder nodes that let you swap out yui engine with GCC (Google Clojure Compiler https://github.com/google/closure-compiler-js). 

For example, see these client library nodes that use GCC for js:
/libs/granite/contexthub/dependencies/coralui
/etc/clientlibs/granite/coralui3
/etc/clientlibs/granite/coralui2
/libs/dam/gui/coral/components/admin/adhocassetshare/clientlibs/adhocassetshare
/libs/dam/gui/components/admin/adhocassetshare/clientlibs/shareembedded
/etc/clientlibs/screens/player/shared
/etc/clientlibs/screens/player/firmware
/libs/dam/gui/components/admin/adhocassetshare/clientlibs/shareembeddedpreview
/apps/geometrixx-instore/clientlibs

In addition, if you want to implement your own custom script processor, then you would implement this java interface:
com.adobe.granite.ui.clientlibs.script.ScriptProcessor

Related javadoc:

https://docs.adobe.com/docs/en/aem/6-2/develop/ref/diff-previous/changes/pkg_com.adobe.granite.ui.clientlibs.script.html

This allows you to define ScriptProcessors that can modify script sources:

  • the processors are configurable with options
  • the processor can be used for minification, but also for non-minified cases
  • a property on the cq:ClientLibraryFolder node allows you to define which processor to use

Configuration:

  • These extra multivalue properties can be set on the cq:ClientLibraryFolder node: cssProcessor and jsProcessor.
  • The default ScriptProcessors options can be set via the HTML Library Manager OSGi configuration (in the /system/console/configMgr UI).

For example, to use YUI compressor for css minification and Google Closure Compiler for JS set these properties on the cq:ClientLibraryFolder node: 

cssProcessor: ["default:none", "min:yui"]
jsProcessor: ["default:none", "min:gcc;compilationLevel=advanced"]
use typescript to preprocess, then gcc to minify and obfuscate:
jsProcessor: [
   "default:typescript",
   "min:typescript", 
   "min:gcc;obfuscate=true"
]

the format is: 

config:= mode ":" processorName options*;
mode:= "default" | "min";
processorName := "none" | ;
options := ";" option;
option := name "=" value;

Options for GCC are:

  • failOnWarning (defaults to "false")
  • languageIn (defaults to "ECMASCRIPT5")
  • languageOut (defaults to "ECMASCRIPT5")
  • compilationLevel (defaults to "simple") (can be "whitespace", "simple", "advanced")

本产品经 Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License 许可  Twitter™ 与 Facebook 中的内容不在 Creative Commons 的条款约束之下。

法律声明   |   在线隐私策略