grunt-aem-clientlib-generator
A Grunt plugin wrapper for aem-clientlib-generator.
Installation
npm install grunt-aem-clientlib-generator
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks("grunt-aem-clientlib-generator");
Usage
Define clientlib
property in your grunt configuration file:
grunt.initConfig({
clientlib: {
options: {
clientLibRoot: "./test/result/clientlibs-root",
cwd: "./test/src/frontend",
"serializationFormat": "json"
},
"test.base.apps.mainapp": {
"js": {
flatten: false,
cwd: "./test/src/frontend/js",
src: [
"**/*.js",
"!app.js",
"app.js"
]
},
"allowProxy": true,
"longCacheKey": "${project.version}-${buildNumber}",
"css": "css/**/*.css"
},
"test.base.apps.secondapp": {
options: {
cwd: "./test/src/frontend/secondapp"
},
"embed": [
"test.base.apps.thirdapp"
],
"dependencies": [
"test.base.apps.mainapp"
],
"cssProcessor": ["default:none", "min:none"],
"jsProcessor": ["default:none", "min:gcc;compilationLevel=whitespace"],
"js": {
src: "js/lib.js",
rename: "secondapp-lib.js"
},
"css": {
base: "style",
src: "main.css"
},
"resources": {
cwd: "./test/src/frontend/",
base: ".",
flatten: false,
src: [
"resources/**",
"!resources/**/*.txt"
]
}
},
"test.base.apps.thirdapp": {
resources: {
base: ".",
flatten: false,
src: [
"resources/**/*.txt"
]
}
},
"test.base.apps.serializationFormatXML": {
options: {
cwd: "./test/src/frontend/secondapp"
},
"serializationFormat": "xml",
"categories": [
"test.base.apps.six",
"test.categorie.in.config"
],
"embed": [
"test.base.apps.thirdapp"
],
"dependencies": "test.base.apps.mainapp",
"js": {
"src": "js/lib.js",
"rename": "secondapp-lib.js"
},
"css": {
base: "style",
src: "main.css"
},
"resources": {
cwd: "./test/src/frontend/",
base: ".",
flatten: false,
src: [
"resources/**",
"!resources/**/*.txt"
]
}
}
}
});
Options
Options can be defined globally and for every task separately. The special file pattern properties
can also be defined for assets.
Global Options
Global options will be used for all defined tasks and asset configurations until the property
will be overridden.
options
{Object}
global configuration properties
clientLibRoot
{String}
Clientlib root path for all clientlibs
cwd
{String}
directory all paths start with; paths are stripped from the beginning
expand
{Boolean}
using glob pattern for file searching (default: true)
flatten
{Boolean}
removes the path component from source, keep the filename (default: true)
filter
{String|Function}
if string it must be a valid fs.Stats method or a function that is passed the matched src
filepath (default: isFile
)
serializationFormat
{String}
Format of clientLib definition, either xml
or json
, default json
clientlib: {
options: {
clientLibRoot: "./test/result/clientlibs-root",
cwd: "./test/src/frontend"
},
}
Task Options
Task options defines properties for a specific clientlib and will override properties from
global options. cwd
, expand
and flatten
will also be used for all asset configurations.
options
{Object}
task configuration properties
path
{String}
Clientlib root path (optional if options.clientLibRoot
is set)
cwd
{String}
directory all paths start with; paths are stripped from the beginning
expand
{Boolean}
using glob pattern for file searching (default: true)
flatten
{Boolean}
removes the path component from source, keep the filename
filter
{String|Function}
if string it must be a valid fs.Stats method or a function that is passed the matched src
filepath (default: isFile
)
clientlib: {
"clientlib.name": {
options: {
clientLibRoot: "./test/result/clientlibs-root",
cwd: "./test/src/frontend"
},
js: { },
...
}
}
ClientLib Configuration
A ClientLib can be configured for each task with the following properties:
embed
{Array<String>}
array of ClientLib names that should be embedded by AEM (optional)
dependencies
{Array<String>}
array of other ClientLib names that should be included by AEM (optional)
cssProcessor
{Array<String>}
array of configuration properties for the ClientLib CSS processor, requires AEM 6.2 (optional)
jsProcessor
{Array<String>}
array of configuration properties for the ClientLib JS processor, requires AEM 6.2 (optional)
allowProxy
{Boolean}
allow for Clientlib creation under /apps/myapp/clientLibs
but enable proxy to /etc.clientlibs/myapp/clientlibs/mylib
See AEM 6.3 Documentation
longCacheKey
{String}
optional string with placeholders to use with URL Fingerprinting, eq. "${project.version}-${buildNumber}"
serializationFormat
{String}
Format of clientLib definition, either xml
or json
, default json
js|css|resources
{Object}
asset configuration properties
cwd
{String}
directory all paths start with; paths are stripped from the beginning
expand
{Boolean}
using glob pattern for file searching (default: true)
flatten
{Boolean}
removes the path component from source, keep the filename
filter
{String|Function}
if string it must be a valid fs.Stats method or a function that is passed the matched src
filepath (default: isFile
)
base
{String}
subpath under clientlib folder where the assets should be copied to (default: asset key, e.g. for
asset configuration "js" is the base folder "js/"; use "." to copy files into the clientlib base)
src
{String|Array<String>}
globbing patterns for filename expansion
rename
{String|Function}
- if a string is defined, a single
src
will be renamed (ensure that src
is a string)
- if a function is specified it will be used for building the destination path for every source path
Important: Keep in mind that the destination path will be used as a relative path to the clientlib base folder.
clientlib: {
"your.clientlib.name": {
"embed": ["other.clientlib.name"],
"jsProcessor": ["default:none", "min:gcc;compilationLevel=whitespace"],
"js": {
flatten: false,
cwd: "./test/src/frontend/js",
src: [
"**/*.js"
]
},
...
}
}