A Vite plugin to copy and structure assets for AEM clientlibs
npm install vite-plugin-aem-clientlibA Vite plugin that generates Adobe AEMβcompatible clientlibs from your built Vite assets.
It handles:
- Copying JS, CSS, images, fonts, source maps into AEM clientlibs folder
- Creating .content.xml, js.txt, and css.txt automatically
- Rewriting sourceMappingURL comments in JS/CSS
- Optional cleanup of previous build output
---
``bash`
npm install --save-dev vite-plugin-aem-clientlib
`
import { defineConfig } from 'vite';
import aemClientlibPlugin, { rewriteAssetFilePaths } from 'vite-plugin-aem-clientlib';
export default defineConfig(({ mode }) => ({
base: '',
build: {
outDir: 'dist',
sourcemap: mode !== 'production',
rollupOptions: {
input: './src/main.js',
output: rewriteAssetFilePaths()
}
},
plugins: [
aemClientlibPlugin({
name: 'your-clientlib',
path: '../ui.apps/src/main/content/jcr_root/apps/your-site/clientlibs/your-clientlib',
includeMaps: mode !== 'production',
dependencies: ['core-clientlib'],
embed: ['shared-ui']
})
]
}));
`π§ Plugin Options
| Option | Type | Required | Description |
| -------------- | ---------- | -------- | ------------------------------------------------------------------------------------------ |
| name | string | β
| Clientlib name (used in .content.xml) |path
| | string | β
| Full local path to your AEM clientlib folder |js
| | string | β | Subfolder name for JS files (default: 'js') |css
| | string | β | Subfolder name for CSS files (default: 'css') |assets
| | string | β | Subfolder under resources/ for assets like fonts/images (default: 'assets') |includeMaps
| | boolean | β | Whether to copy source map files and rewrite sourceMappingURL comments (default: true) |clean
| | boolean | β | If true, deletes the target clientlib folder before writing (default: true) |allowProxy
| | boolean | β | Adds allowProxy="{Boolean}true" to .content.xml (default: true) |dependencies
| | string[] | β | Array of AEM clientlibs this clientlib depends on |embed
| | string[] | β | Array of AEM clientlibs this one embeds/inlines |
, the plugin generates:
`
clientlibs/my-clientlib/
βββ js/
β βββ main.js
βββ css/
β βββ app.css
βββ resources/
β βββ assets/
β β βββ Inter.woff2
β β βββ logo.svg
β βββ maps/
β βββ main.js.map
β βββ app.css.map
βββ js.txt
βββ css.txt
βββ .content.xml
`
π¦ .content.xml Example
`
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
categories="[my-clientlib]"
dependencies="[core-clientlib]"
embed="[shared-ui]"
allowProxy="{Boolean}true"/>
``