// path: A Node.js module used to handle and manipulate file paths.
// { dependencies } = require("webpack"): Extracts dependencies from Webpack, but this isn't actually used later in the file.
const path = require("path");
const { dependencies } = require("webpack");
// BUILD_DIR: The output directory where Webpack compiles assets (dist as we discssued above it contain our all complied css+js).
// CLIENTLIB_DIR: The directory inside the AEM project where the ClientLibs are stored (/apps/projectname/clientlibs .
const BUILD_DIR = path.join(__dirname, "dist");
const CLIENTLIB_DIR = path.join(
__dirname,
"..",
"ui.apps",
"src",
"main",
"content",
"jcr_root",
"apps",
"projectName",
"clientlibs"
);
// 1. allowProxy: true: Allows accessing the client libraries via /etc.clientlibs/ instead of /apps/eti/clientlibs/.
// 2. serializationFormat: "xml": Defines the format for ClientLibs in AEM (used in .content.xml files).
// 3. cssProcessor: ["default:none", "min:none"]: Disables CSS minification.
// 4. jsProcessor: ["default:none", "min:none"]: Disables JavaScript minification.
const libsBaseConfig = {
allowProxy: true,
serializationFormat: "xml",
cssProcessor: ["default:none", "min:none"],
jsProcessor: ["default:none", "min:none"],
};
// context: BUILD_DIR: Sets the build directory as the working context.
// clientLibRoot: CLIENTLIB_DIR: Specifies the target directory inside AEM where the client libraries
module.exports = {
context: BUILD_DIR,
clientLibRoot: CLIENTLIB_DIR,
// libs: An array containing multiple ClientLibs definitions.
libs: [
// This defines a ClientLib named clientlib-dependencies:
// categories: ["eti.dependencies"]: Used to include this ClientLib in AEM components.
// cwd: "clientlib-dependencies": Looks for assets inside the clientlib-dependencies folder.
// files: ["**/*.js"], ["**/*.css"]: Copies all JavaScript and CSS files.
{
...libsBaseConfig,
name: "clientlib-dependencies",
categories: ["projectName.dependencies"],
assets: {
// Copy entrypoint scripts and stylesheets into the respective ClientLib
// directories
js: {
cwd: "clientlib-dependencies",
files: ["**/*.js"],
flatten: false,
},
css: {
cwd: "clientlib-dependencies",
files: ["**/*.css"],
flatten: false,
},
},
},
// Defines a ClientLib named clientlib-site:
// categories: ["eti.site"]: Used to load this ClientLib in AEM components.
// dependencies: ["eti.dependencies"]: Ensures that clientlib-dependencies is loaded first.
// Also includes non-JS/CSS files in resources, ignoring JS and CSS
{
...libsBaseConfig,
name: "clientlib-site",
categories: ["projectName.site"],
dependencies: ["projectName.dependencies"],
assets: {
// Copy entrypoint scripts and stylesheets into the respective ClientLib
// directories
js: {
cwd: "clientlib-site",
files: ["**/*.js"],
flatten: false,
},
css: {
cwd: "clientlib-site",
files: ["**/*.css"],
flatten: false,
},
// Copy all other files into the `resources` ClientLib directory
resources: {
cwd: "clientlib-site",
files: ["**/*.*"],
flatten: false,
ignore: ["**/*.js", "**/*.css"],
},
},
},
// Defines ClientLib clientlib-projectName:
// categories: ["projectName-site"]: Used in AEM components.
// dependencies: ["projectName.dependencies"]: Ensures dependent scripts load first.
// Similar to clientlib-site, it includes JS, CSS, and other assets.
{
...libsBaseConfig,
name: "clientlib-projectName",
categories: ["projectName-site"],
dependencies: ["projectName.dependencies"],
assets: {
// Copy entrypoint scripts and stylesheets into the respective ClientLib
// directories
js: {
cwd: "clientlib-projectName",
files: ["**/*.js"],
flatten: false,
},
css: {
cwd: "clientlib-projectName",
files: ["**/*.css"],
flatten: false,
},
// Copy all other files into the `resources` ClientLib directory
resources: {
cwd: "clientlib-projectName",
files: ["**/*.*"],
flatten: false,
ignore: ["**/*.js", "**/*.css"],
},
},
},
],
};