### Build Web Assets (Deprecated) Source: https://context7.com/adobe/aio-lib-web/llms.txt Legacy function for building web assets. Deprecated in favor of the `bundle` function. ```APIDOC ## POST /buildWeb [Deprecated] ### Description Legacy function for building web assets. Deprecated since version 4.1.0 in favor of the `bundle` function. Bundles the application's static files from the source directory to the production distribution directory using Parcel. ### Method POST ### Endpoint /buildWeb ### Parameters #### Request Body - **config** (object) - Required - Configuration object structure, including `app.hasFrontend` and `web.src`, `web.distProd`. - **log** (function) - Optional - A logger function to receive build messages. ### Request Example ```javascript const { buildWeb } = require('@adobe/aio-lib-web'); // Configuration object structure const config = { app: { hasFrontend: true }, web: { src: 'web-src', distProd: 'dist/web-prod' } }; // Build with logging const builtFiles = await buildWeb(config, (msg) => console.log(msg)); // Build without logging const files = await buildWeb(config); console.log('Built files:', files); ``` ### Response #### Success Response (200) - **builtFiles** (array) - An array of strings representing the names of the built files. #### Response Example ```json [ "index.html", "index.abc123.js", "index.def456.css" ] ``` ``` -------------------------------- ### Bundle Web Assets Source: https://context7.com/adobe/aio-lib-web/llms.txt Creates a Parcel bundler instance for bundling web application source files. This is the recommended method for building web assets. ```APIDOC ## POST /bundle ### Description Creates a Parcel bundler instance for bundling web application source files. This is the recommended method for building web assets, replacing the deprecated `buildWeb` function. Returns a configured Parcel bundler object that can be used for both single builds and watch mode. ### Method POST ### Endpoint /bundle ### Parameters #### Query Parameters - **entries** (string | string[]) - Required - The entry point(s) for the bundle (e.g., 'web-src/index.html'). - **dest** (string) - Required - The output directory for the bundled files (e.g., 'dist/web'). - **options** (object) - Optional - Parcel options for customization (e.g., `{ shouldOptimize: false }`). - **log** (function) - Optional - A logger function to receive build messages. ### Request Example ```javascript const { bundle } = require('@adobe/aio-lib-web'); // Basic bundling with default options const bundler = await bundle( 'web-src/index.html', // Entry point(s) - can be string or array 'dist/web', // Output directory { shouldOptimize: false } // Parcel options ); // Run the bundler await bundler.run(); // Advanced usage with multiple entries and optimization const bundlerOptimized = await bundle( ['web-src/index.html', 'web-src/admin.html'], 'dist/web-prod', { shouldOptimize: true, shouldDisableCache: false, shouldContentHash: true, logLevel: 'error' }, (msg) => console.log(msg) // Optional logger function ); await bundlerOptimized.run(); // Watch mode for development const devBundler = await bundle('web-src/index.html', 'dist/web-dev', { shouldOptimize: false, shouldDisableCache: true }); const subscription = await devBundler.watch(); // Later: await subscription.unsubscribe(); ``` ### Response #### Success Response (200) - **bundler** (object) - A configured Parcel bundler object with a `run()` method and potentially a `watch()` method for development. #### Response Example ```json { "message": "Bundler created successfully" } ``` ``` -------------------------------- ### Deploy Web Assets to Adobe CDN Source: https://context7.com/adobe/aio-lib-web/llms.txt Deploys bundled static web assets to Adobe's CDN using S3 storage. It handles credential retrieval (TVM or BYO), checks for existing deployments, and uploads files with appropriate MIME types and cache control headers. Configuration options include cache durations and custom response headers. ```javascript const { deployWeb } = require('@adobe/aio-lib-web'); // Configuration with TVM credentials (Adobe I/O Runtime) const config = { app: { hasFrontend: true, hostname: 'adobeioruntime.net', htmlCacheDuration: 60, // Cache HTML for 60 seconds jsCacheDuration: 604800, // Cache JS for 1 week cssCacheDuration: 604800, // Cache CSS for 1 week imageCacheDuration: 604800 // Cache images for 1 week }, ow: { namespace: 'my-namespace', auth: 'my-auth-key' }, s3: { folder: 'my-namespace/my-app', tvmUrl: 'https://firefly-tvm.adobe.io', // Optional custom TVM URL credsCacheFile: '.aws.tmp.creds.json' // Optional credentials cache }, web: { distProd: 'dist/web-prod', 'response-headers': { '/*': { 'X-Frame-Options': 'DENY' }, '/*.html': { 'cache-control': 'max-age=60, s-maxage=300' } } } }; // Deploy with progress logging const deployedUrl = await deployWeb(config, (msg) => console.log(msg)); // Output: // deploying index.html // deploying index.abc123.js // deploying index.def456.css console.log('Deployed to:', deployedUrl); // https://my-namespace.adobeioruntime.net/index.html // Configuration with BYO S3 credentials const byoConfig = { app: { hasFrontend: true, hostname: 'custom-cdn.example.com' }, ow: { namespace: 'custom-namespace' }, s3: { folder: 'web-assets/my-app', creds: { accessKeyId: 'AKIAIOSFODNN7EXAMPLE', secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', sessionToken: 'optional-session-token', // Optional params: { Bucket: 'my-custom-bucket' } } }, web: { distProd: 'dist/web-prod' } }; const customUrl = await deployWeb(byoConfig); ``` -------------------------------- ### Configure Response Headers for Web Assets Source: https://context7.com/adobe/aio-lib-web/llms.txt Configure custom HTTP response headers for deployed assets based on path rules. Headers are applied during upload and served by the CDN. This configuration is part of the `web` section in the library's configuration object. ```javascript const { deployWeb } = require('@adobe/aio-lib-web'); const config = { app: { hasFrontend: true, hostname: 'adobeioruntime.net' }, ow: { namespace: 'my-namespace', auth: 'my-auth-key' }, s3: { folder: 'my-namespace/my-app' }, web: { distProd: 'dist/web-prod', 'response-headers': { // Apply to all files '/*': { 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'SAMEORIGIN' }, // Apply to all HTML files '/*.html': { 'cache-control': 'max-age=60, s-maxage=300', 'Content-Security-Policy': "default-src 'self'" }, // Apply to all files in /assets/ folder '/assets/*': { 'cache-control': 'max-age=31536000, immutable' }, // Apply to specific file types in a folder '/scripts/*.js': { 'cache-control': 'max-age=604800' }, // Apply to a specific file '/config.json': { 'cache-control': 'no-cache, no-store' } } } }; await deployWeb(config, console.log); ``` -------------------------------- ### Build Web Assets using Deprecated buildWeb Function Source: https://context7.com/adobe/aio-lib-web/llms.txt Legacy function for building web assets, deprecated in favor of the `bundle` function. It bundles static files from a source directory to a production distribution directory using Parcel. It requires a configuration object and an optional logger function. ```javascript const { buildWeb } = require('@adobe/aio-lib-web'); // Configuration object structure const config = { app: { hasFrontend: true }, web: { src: 'web-src', // Source directory containing index.html distProd: 'dist/web-prod' // Output directory for bundled files } }; // Build with logging const builtFiles = await buildWeb(config, (msg) => console.log(msg)); // Output: ['index.html', 'index.abc123.js', 'index.def456.css', ...] // Build without logging const files = await buildWeb(config); console.log('Built files:', files); ``` -------------------------------- ### Bundle Web Assets with Parcel using @adobe/aio-lib-web Source: https://context7.com/adobe/aio-lib-web/llms.txt Creates a Parcel bundler instance for bundling web application source files. This function supports basic bundling, advanced configurations with multiple entries and optimizations, and watch mode for development. It takes entry points, an output directory, Parcel options, and an optional logger function as input. ```javascript const { bundle } = require('@adobe/aio-lib-web'); // Basic bundling with default options const bundler = await bundle( 'web-src/index.html', // Entry point(s) - can be string or array 'dist/web', // Output directory { shouldOptimize: false } // Parcel options ); // Run the bundler await bundler.run(); // Advanced usage with multiple entries and optimization const bundlerOptimized = await bundle( ['web-src/index.html', 'web-src/admin.html'], 'dist/web-prod', { shouldOptimize: true, // Enable minification shouldDisableCache: false, // Use Parcel cache shouldContentHash: true, // Add content hashes to filenames logLevel: 'error' // Parcel log level }, (msg) => console.log(msg) // Optional logger function ); await bundlerOptimized.run(); // Watch mode for development const devBundler = await bundle('web-src/index.html', 'dist/web-dev', { shouldOptimize: false, shouldDisableCache: true }); const subscription = await devBundler.watch(); // Later: await subscription.unsubscribe(); ``` -------------------------------- ### Undeploy Web Assets from Adobe CDN Source: https://context7.com/adobe/aio-lib-web/llms.txt Removes all deployed static files from the CDN storage, useful for cleanup or decommissioning applications. This function requires the same configuration structure as the `deployWeb` function to identify the assets to be removed. ```javascript const { undeployWeb } = require('@adobe/aio-lib-web'); const config = { app: { hasFrontend: true }, ow: { namespace: 'my-namespace', auth: 'my-auth-key' }, s3: { folder: 'my-namespace/my-app' } }; try { await undeployWeb(config); console.log('Successfully removed all deployed web assets'); } catch (error) { if (error.message.includes('there is no deployment')) { console.log('No deployment found to remove'); } else { throw error; } } ``` -------------------------------- ### Manage S3 Storage Operations with RemoteStorage Source: https://context7.com/adobe/aio-lib-web/llms.txt The `RemoteStorage` class provides internal functionality for managing S3 storage operations. It can be instantiated directly for advanced use cases, allowing fine-grained control over uploading, checking existence, and emptying folders within S3 buckets. It supports credential management via TVM or direct credential provision. ```javascript const RemoteStorage = require('@adobe/aio-lib-web/lib/remote-storage'); // Initialize with TVM credentials const credentials = { accessKeyId: 'AKIAIOSFODNN7EXAMPLE', secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', sessionToken: 'FwoGZXIvYXdzEBYaDH...', // Optional for temporary creds expiration: '2024-01-15T12:00:00Z', // Optional params: { Bucket: 'my-bucket' } }; const storage = new RemoteStorage(credentials); // Check if a folder/prefix exists const exists = await storage.folderExists('my-namespace/my-app/'); console.log('Deployment exists:', exists); // Upload a single file const appConfig = { app: { htmlCacheDuration: 60, jsCacheDuration: 604800 }, web: { 'response-headers': { '/*': { 'X-Content-Type-Options': 'nosniff' } } } }; await storage.uploadFile('dist/index.html', 'my-prefix', appConfig, 'dist'); // Upload entire directory with callback await storage.uploadDir( 'dist/web-prod', // Local directory 'my-namespace/my-app', // Remote prefix appConfig, (filePath) => console.log(`Uploaded: ${filePath}`) ); // Empty a folder (delete all files) await storage.emptyFolder('my-namespace/my-app/'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.