From a8230a83606fa45918a94cb60fe5b0d613243490 Mon Sep 17 00:00:00 2001 From: "Bajohr, Rayk" Date: Thu, 18 Jun 2026 10:10:24 +0200 Subject: [PATCH] feat(live-preview): provide custom builder with esbuild plugins --- .gitignore | 3 + angular.json | 4 +- eslint.config.js | 4 +- package-lock.json | 208 ----- package.json | 3 +- projects/live-preview/builders.json | 15 + .../builders/src/application/index.ts | 43 + .../builders/src/application/schema.json | 738 ++++++++++++++++++ .../builders/src/dev-server/index.ts | 38 + .../builders/src/dev-server/patch-context.ts | 31 + .../builders/src/dev-server/schema.json | 144 ++++ projects/live-preview/builders/src/index.ts | 6 + .../live-preview/builders/src/load-plugins.ts | 56 ++ projects/live-preview/builders/tsconfig.json | 15 + projects/live-preview/ng-package.json | 9 +- projects/live-preview/package.json | 4 + 16 files changed, 1106 insertions(+), 215 deletions(-) create mode 100644 projects/live-preview/builders.json create mode 100644 projects/live-preview/builders/src/application/index.ts create mode 100755 projects/live-preview/builders/src/application/schema.json create mode 100644 projects/live-preview/builders/src/dev-server/index.ts create mode 100644 projects/live-preview/builders/src/dev-server/patch-context.ts create mode 100644 projects/live-preview/builders/src/dev-server/schema.json create mode 100644 projects/live-preview/builders/src/index.ts create mode 100644 projects/live-preview/builders/src/load-plugins.ts create mode 100644 projects/live-preview/builders/tsconfig.json diff --git a/.gitignore b/.gitignore index d1a8f7cf9d..0d855fb6c7 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,6 @@ Thumbs.db # EsLint cache .eslintcache + +# Angular builder +projects/live-preview/builders/dist diff --git a/angular.json b/angular.json index 7c88fd3801..26711a91e6 100644 --- a/angular.json +++ b/angular.json @@ -8,7 +8,7 @@ "prefix": "app", "architect": { "build": { - "builder": "@angular-builders/custom-esbuild:application", + "builder": "@siemens/live-preview:application", "options": { "plugins": ["projects/live-preview/esbuild-component-loader.mjs"], "outputPath": { @@ -108,7 +108,7 @@ } }, "serve": { - "builder": "@angular-builders/custom-esbuild:dev-server", + "builder": "@siemens/live-preview:dev-server", "options": { "buildTarget": "element-examples:build" }, diff --git a/eslint.config.js b/eslint.config.js index f5c0efb38d..9e3b8536ea 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -5,13 +5,13 @@ import angularTemplateConfig from '@siemens/eslint-config-angular/template'; import vitest from '@vitest/eslint-plugin'; import tsdocPlugin from 'eslint-plugin-tsdoc'; import eslintPluginHeaders from 'eslint-plugin-headers'; -import { defineConfig } from 'eslint/config'; +import { defineConfig, globalIgnores } from 'eslint/config'; // mimic CommonJS variables const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -export const tsConfig = defineConfig({ +export const tsConfig = defineConfig(globalIgnores(['**/dist/']), { extends: [...angularTypescriptConfig], files: ['**/*.ts'], languageOptions: { diff --git a/package-lock.json b/package-lock.json index 5f765ce5ee..06497c92fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,7 +55,6 @@ "tslib": "2.8.1" }, "devDependencies": { - "@angular-builders/custom-esbuild": "21.0.3", "@angular-devkit/build-angular": "21.0.5", "@angular-devkit/core": "21.0.5", "@angular-devkit/schematics": "21.0.5", @@ -495,41 +494,6 @@ "signale": "^1.4.0" } }, - "node_modules/@angular-builders/common": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/@angular-builders/common/-/common-5.0.3.tgz", - "integrity": "sha512-Dro3574mu4/xqmjdA3159+TXDhgTbIJpEY/iBETSKUvHJiCgHel+R3eT105RpHN5o7NaD2rau5Zk2wuZqOk35Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "@angular-devkit/core": "^21.0.0", - "ts-node": "^10.0.0", - "tsconfig-paths": "^4.2.0" - }, - "engines": { - "node": "^20.19.0 || ^22.12.0 || >=24.0.0" - } - }, - "node_modules/@angular-builders/custom-esbuild": { - "version": "21.0.3", - "resolved": "https://registry.npmjs.org/@angular-builders/custom-esbuild/-/custom-esbuild-21.0.3.tgz", - "integrity": "sha512-Q56JTNVrmdm2XJEHu3HWsTcxXMREYZ2ROnuaUs7ZV02Tu8E9Y8ejk8LCsRFNe/LKciUUMzaM6B78nSkXrkkNjQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@angular-builders/common": "5.0.3", - "@angular-devkit/architect": ">=0.2100.0 < 0.2200.0", - "@angular-devkit/core": "^21.0.0", - "@angular/build": "^21.0.0" - }, - "engines": { - "node": "^20.19.0 || ^22.12.0 || >=24.0.0" - }, - "peerDependencies": { - "@angular/compiler-cli": "^21.0.0", - "vitest": ">=2" - } - }, "node_modules/@angular-devkit/architect": { "version": "0.2102.9", "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.2102.9.tgz", @@ -5894,30 +5858,6 @@ } } }, - "node_modules/@cspotcode/source-map-support": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", - "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@jridgewell/trace-mapping": "0.3.9" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", - "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@jridgewell/resolve-uri": "^3.0.3", - "@jridgewell/sourcemap-codec": "^1.4.10" - } - }, "node_modules/@csstools/css-calc": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-3.2.1.tgz", @@ -12188,34 +12128,6 @@ "tinyglobby": "^0.2.14" } }, - "node_modules/@tsconfig/node10": { - "version": "1.0.12", - "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.12.tgz", - "integrity": "sha512-UCYBaeFvM11aU2y3YPZ//O5Rhj+xKyzy7mvcIoAjASbigy8mHMryP5cK7dgjlz2hWxh1g5pLw084E0a/wlUSFQ==", - "dev": true, - "license": "MIT" - }, - "node_modules/@tsconfig/node12": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", - "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", - "dev": true, - "license": "MIT" - }, - "node_modules/@tsconfig/node14": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", - "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", - "dev": true, - "license": "MIT" - }, - "node_modules/@tsconfig/node16": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", - "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", - "dev": true, - "license": "MIT" - }, "node_modules/@tufjs/canonical-json": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tufjs/canonical-json/-/canonical-json-2.0.0.tgz", @@ -13416,19 +13328,6 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, - "node_modules/acorn-walk": { - "version": "8.3.5", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.5.tgz", - "integrity": "sha512-HEHNfbars9v4pgpW6SO1KSPkfoS0xVOM/9UzkJltjlsHZmJasxg8aXkuZa7SMf8vKGIBhpUsPluQSqhJFCqebw==", - "dev": true, - "license": "MIT", - "dependencies": { - "acorn": "^8.11.0" - }, - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/adjust-sourcemap-loader": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/adjust-sourcemap-loader/-/adjust-sourcemap-loader-4.0.0.tgz", @@ -13741,13 +13640,6 @@ ], "license": "MIT" }, - "node_modules/arg": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", - "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", - "dev": true, - "license": "MIT" - }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -15412,13 +15304,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/create-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", - "dev": true, - "license": "MIT" - }, "node_modules/cron-parser": { "version": "4.9.0", "resolved": "https://registry.npmjs.org/cron-parser/-/cron-parser-4.9.0.tgz", @@ -19720,13 +19605,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/make-error": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true, - "license": "ISC" - }, "node_modules/make-fetch-happen": { "version": "15.0.5", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-15.0.5.tgz", @@ -27530,75 +27408,6 @@ "code-block-writer": "^13.0.3" } }, - "node_modules/ts-node": { - "version": "10.9.2", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", - "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@cspotcode/source-map-support": "^0.8.0", - "@tsconfig/node10": "^1.0.7", - "@tsconfig/node12": "^1.0.7", - "@tsconfig/node14": "^1.0.0", - "@tsconfig/node16": "^1.0.2", - "acorn": "^8.4.1", - "acorn-walk": "^8.1.1", - "arg": "^4.1.0", - "create-require": "^1.1.0", - "diff": "^4.0.1", - "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.1", - "yn": "3.1.1" - }, - "bin": { - "ts-node": "dist/bin.js", - "ts-node-cwd": "dist/bin-cwd.js", - "ts-node-esm": "dist/bin-esm.js", - "ts-node-script": "dist/bin-script.js", - "ts-node-transpile-only": "dist/bin-transpile.js", - "ts-script": "dist/bin-script-deprecated.js" - }, - "peerDependencies": { - "@swc/core": ">=1.2.50", - "@swc/wasm": ">=1.2.50", - "@types/node": "*", - "typescript": ">=2.7" - }, - "peerDependenciesMeta": { - "@swc/core": { - "optional": true - }, - "@swc/wasm": { - "optional": true - } - } - }, - "node_modules/ts-node/node_modules/diff": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.4.tgz", - "integrity": "sha512-X07nttJQkwkfKfvTPG/KSnE2OMdcUCao6+eXF3wmnIQRn2aPAHH3VxDbDOdegkd6JbPsXqShpvEOHfAT+nCNwQ==", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/tsconfig-paths": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", - "integrity": "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==", - "dev": true, - "license": "MIT", - "dependencies": { - "json5": "^2.2.2", - "minimist": "^1.2.6", - "strip-bom": "^3.0.0" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", @@ -28532,13 +28341,6 @@ "uuid": "dist/bin/uuid" } }, - "node_modules/v8-compile-cache-lib": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", - "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", - "dev": true, - "license": "MIT" - }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -30382,16 +30184,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/yn": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", - "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index c1f6ed705b..a243fbbd79 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "docs:serve:generate": "cross-env DOCS_COMPOSER=true DOCS_COMPOSER_GENERATE=true uv run mkdocs serve", "icon-viewer:build-docs": "ng build icon-viewer --configuration=production", "icon-viewer:serve": "ng serve icon-viewer", - "live-preview:build": "ng build live-preview && cpy LICENSE.md \"./dist/@siemens/live-preview/\"", + "live-preview:build": "tsc -p projects/live-preview/builders/tsconfig.json && cpy projects/live-preview/builders/src/application/schema.json projects/live-preview/builders/dist/application/ && cpy projects/live-preview/builders/src/dev-server/schema.json projects/live-preview/builders/dist/dev-server/ && ng build live-preview && cpy LICENSE.md \"./dist/@siemens/live-preview/\"", "prepare": "husky; exit 0", "prepare-brand": "cpy --flat node_modules/@simpl/brand/assets/favicon/sie-favicon_internet_64px.png docs/_src --rename=favicon.png && cpy --flat node_modules/@simpl/brand/assets/favicon/sie-favicon_internet_64px.png src --rename=favicon.png && cpy --flat node_modules/@simpl/brand/assets/favicon/sie-favicon_internet_64px.png projects/dashboards-demo/src --rename=favicon.png && cpy --flat node_modules/@simpl/brand/assets/favicon/sie-favicon_internet_64px.png projects/dashboards-demo/mfe/src --rename=favicon.png", "postversion": "npm run format", @@ -123,7 +123,6 @@ "tslib": "2.8.1" }, "devDependencies": { - "@angular-builders/custom-esbuild": "21.0.3", "@angular-devkit/build-angular": "21.0.5", "@angular-devkit/core": "21.0.5", "@angular-devkit/schematics": "21.0.5", diff --git a/projects/live-preview/builders.json b/projects/live-preview/builders.json new file mode 100644 index 0000000000..dac9ec05a4 --- /dev/null +++ b/projects/live-preview/builders.json @@ -0,0 +1,15 @@ +{ + "$schema": "./node_modules/@angular-devkit/architect/src/builders-schema.json", + "builders": { + "application": { + "implementation": "./builders/dist/application", + "schema": "./builders/dist/application/schema.json", + "description": "Angular application builder with custom esbuild plugin support" + }, + "dev-server": { + "implementation": "./builders/dist/dev-server", + "schema": "./builders/dist/dev-server/schema.json", + "description": "Angular dev-server with custom esbuild plugin support" + } + } +} diff --git a/projects/live-preview/builders/src/application/index.ts b/projects/live-preview/builders/src/application/index.ts new file mode 100644 index 0000000000..82954d945a --- /dev/null +++ b/projects/live-preview/builders/src/application/index.ts @@ -0,0 +1,43 @@ +/** + * Copyright (c) Siemens 2016 - 2026 + * SPDX-License-Identifier: MIT + */ +import { createBuilder, type BuilderOutput } from '@angular-devkit/architect'; +import { buildApplication, type ApplicationBuilderOptions } from '@angular/build'; + +import { loadPlugins } from '../load-plugins.js'; + +interface ApplicationOptions extends ApplicationBuilderOptions { + plugins?: string[]; +} + +export default createBuilder( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + async (options: ApplicationOptions, context: any): Promise => { + const plugins = options.plugins ? await loadPlugins(options.plugins, context) : []; + + const buildOptions = { ...options } as ApplicationBuilderOptions; + delete (buildOptions as Record).plugins; + + try { + for await (const output of buildApplication( + buildOptions, + context as Parameters[1], + { codePlugins: plugins } + )) { + if (!output.success) { + return output; + } + } + + return { success: true }; + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error); + context.logger.error(`Build failed: ${errorMessage}`); + return { + success: false, + error: errorMessage + }; + } + } +); diff --git a/projects/live-preview/builders/src/application/schema.json b/projects/live-preview/builders/src/application/schema.json new file mode 100755 index 0000000000..8c4307cc32 --- /dev/null +++ b/projects/live-preview/builders/src/application/schema.json @@ -0,0 +1,738 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "title": "Application builder with esbuild plugin support", + "description": "Application builder with custom esbuild plugin support. Accepts all options from @angular/build:application.", + "type": "object", + "properties": { + "plugins": { + "type": "array", + "description": "List of paths to esbuild plugins. Each path should resolve to a module that exports an esbuild Plugin or Plugin array.", + "items": { + "type": "string" + }, + "default": [] + }, + "assets": { + "type": "array", + "description": "Define the assets to be copied to the output directory. These assets are copied as-is without any further processing or hashing.", + "default": [], + "items": { + "$ref": "#/definitions/assetPattern" + } + }, + "browser": { + "type": "string", + "description": "The full path for the browser entry point to the application, relative to the current workspace." + }, + "server": { + "description": "The full path for the server entry point to the application, relative to the current workspace.", + "oneOf": [ + { + "type": "string", + "description": "The full path for the server entry point to the application, relative to the current workspace." + }, + { + "const": false, + "type": "boolean", + "description": "Indicates that a server entry point is not provided." + } + ] + }, + "polyfills": { + "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.", + "type": "array", + "items": { + "type": "string", + "uniqueItems": true + }, + "default": [] + }, + "tsConfig": { + "type": "string", + "description": "The full path for the TypeScript configuration file, relative to the current workspace." + }, + "deployUrl": { + "type": "string", + "description": "Customize the base path for the URLs of resources in 'index.html' and component stylesheets. This option is only necessary for specific deployment scenarios, such as with Angular Elements or when utilizing different CDN locations." + }, + "security": { + "description": "Security features to protect against XSS and other common attacks", + "type": "object", + "additionalProperties": false, + "properties": { + "allowedHosts": { + "description": "A list of hostnames that are allowed to access the server-side application. For more information, see https://angular.dev/best-practices/security#preventing-server-side-request-forgery-ssrf.", + "type": "array", + "uniqueItems": true, + "items": { + "type": "string" + } + }, + "autoCsp": { + "description": "Enables automatic generation of a hash-based Strict Content Security Policy (https://web.dev/articles/strict-csp#choose-hash) based on scripts in index.html. Will default to true once we are out of experimental/preview phases.", + "default": false, + "oneOf": [ + { + "type": "object", + "properties": { + "unsafeEval": { + "type": "boolean", + "description": "Include the `unsafe-eval` directive (https://web.dev/articles/strict-csp#remove-eval) in the auto-CSP. Please only enable this if you are absolutely sure that you need to, as allowing calls to eval will weaken the XSS defenses provided by the auto-CSP.", + "default": false + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + } + } + }, + "scripts": { + "description": "Global scripts to be included in the build.", + "type": "array", + "default": [], + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "input": { + "type": "string", + "description": "The file to include.", + "pattern": "\\.[cm]?jsx?$" + }, + "bundleName": { + "type": "string", + "pattern": "^[\\w\\-.]*$", + "description": "The bundle name for this extra entry point." + }, + "inject": { + "type": "boolean", + "description": "If the bundle will be referenced in the HTML file.", + "default": true + } + }, + "additionalProperties": false, + "required": ["input"] + }, + { + "type": "string", + "description": "The JavaScript/TypeScript file or package containing the file to include." + } + ] + } + }, + "styles": { + "description": "Global styles to be included in the build.", + "type": "array", + "default": [], + "items": { + "oneOf": [ + { + "type": "object", + "properties": { + "input": { + "type": "string", + "description": "The file to include.", + "pattern": "\\.(?:css|scss|sass|less)$" + }, + "bundleName": { + "type": "string", + "pattern": "^[\\w\\-.]*$", + "description": "The bundle name for this extra entry point." + }, + "inject": { + "type": "boolean", + "description": "If the bundle will be referenced in the HTML file.", + "default": true + } + }, + "additionalProperties": false, + "required": ["input"] + }, + { + "type": "string", + "description": "The file to include.", + "pattern": "\\.(?:css|scss|sass|less)$" + } + ] + } + }, + "inlineStyleLanguage": { + "description": "The stylesheet language to use for the application's inline component styles.", + "type": "string", + "default": "css", + "enum": ["css", "less", "sass", "scss"] + }, + "stylePreprocessorOptions": { + "description": "Options to pass to style preprocessors.", + "type": "object", + "properties": { + "includePaths": { + "description": "Paths to include. Paths will be resolved to workspace root.", + "type": "array", + "items": { + "type": "string" + }, + "default": [] + }, + "sass": { + "description": "Options to pass to the sass preprocessor.", + "type": "object", + "properties": { + "fatalDeprecations": { + "description": "A set of deprecations to treat as fatal. If a deprecation warning of any provided type is encountered during compilation, the compiler will error instead. If a Version is provided, then all deprecations that were active in that compiler version will be treated as fatal.", + "type": "array", + "items": { + "type": "string" + } + }, + "silenceDeprecations": { + "description": " A set of active deprecations to ignore. If a deprecation warning of any provided type is encountered during compilation, the compiler will ignore it instead.", + "type": "array", + "items": { + "type": "string" + } + }, + "futureDeprecations": { + "description": "A set of future deprecations to opt into early. Future deprecations passed here will be treated as active by the compiler, emitting warnings as necessary.", + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "externalDependencies": { + "description": "Exclude the listed external dependencies from being bundled into the bundle. Instead, the created bundle relies on these dependencies to be available during runtime. Note: `@foo/bar` marks all paths within the `@foo/bar` package as external, including sub-paths like `@foo/bar/baz`.", + "type": "array", + "items": { + "type": "string" + }, + "default": [] + }, + "clearScreen": { + "type": "boolean", + "default": false, + "description": "Automatically clear the terminal screen during rebuilds." + }, + "optimization": { + "description": "Enables optimization of the build output. Including minification of scripts and styles, tree-shaking, dead-code elimination, inlining of critical CSS and fonts inlining. For more information, see https://angular.dev/reference/configs/workspace-config#optimization-configuration.", + "default": true, + "x-user-analytics": "ep.ng_optimization", + "oneOf": [ + { + "type": "object", + "properties": { + "scripts": { + "type": "boolean", + "description": "Enables optimization of the scripts output.", + "default": true + }, + "styles": { + "description": "Enables optimization of the styles output.", + "default": true, + "oneOf": [ + { + "type": "object", + "properties": { + "minify": { + "type": "boolean", + "description": "Minify CSS definitions by removing extraneous whitespace and comments, merging identifiers and minimizing values.", + "default": true + }, + "inlineCritical": { + "type": "boolean", + "description": "Extract and inline critical CSS definitions to improve first paint time.", + "default": true + }, + "removeSpecialComments": { + "type": "boolean", + "description": "Remove comments in global CSS that contains '@license' or '@preserve' or that starts with '//!' or '/*!'.", + "default": true + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + }, + "fonts": { + "description": "Enables optimization for fonts. This option requires internet access. `HTTPS_PROXY` environment variable can be used to specify a proxy server.", + "default": true, + "oneOf": [ + { + "type": "object", + "properties": { + "inline": { + "type": "boolean", + "description": "Reduce render blocking requests by inlining external Google Fonts and Adobe Fonts CSS definitions in the application's HTML index file. This option requires internet access. `HTTPS_PROXY` environment variable can be used to specify a proxy server.", + "default": true + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + }, + "loader": { + "description": "Defines the type of loader to use with a specified file extension when used with a JavaScript `import`. `text` inlines the content as a string; `binary` inlines the content as a Uint8Array; `file` emits the file and provides the runtime location of the file; `dataurl` inlines the content as a data URL with best guess of MIME type; `base64` inlines the content as a Base64-encoded string; `empty` considers the content to be empty and not include it in bundles.", + "type": "object", + "patternProperties": { + "^\\.\\S+$": { + "enum": ["text", "binary", "file", "dataurl", "base64", "empty"] + } + } + }, + "define": { + "description": "Defines global identifiers that will be replaced with a specified constant value when found in any JavaScript or TypeScript code including libraries. The value will be used directly. String values must be put in quotes. Identifiers within Angular metadata such as Component Decorators will not be replaced.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "conditions": { + "description": "Custom package resolution conditions used to resolve conditional exports/imports. Defaults to ['module', 'development'/'production']. The following special conditions are always present if the requirements are satisfied: 'default', 'import', 'require', 'browser', 'node'.", + "type": "array", + "items": { + "type": "string" + } + }, + "fileReplacements": { + "description": "Replace compilation source files with other compilation source files in the build.", + "type": "array", + "items": { + "$ref": "#/definitions/fileReplacement" + }, + "default": [] + }, + "outputPath": { + "description": "Specify the output path relative to workspace root.", + "oneOf": [ + { + "type": "object", + "properties": { + "base": { + "type": "string", + "description": "Specify the output path relative to workspace root." + }, + "browser": { + "type": "string", + "pattern": "^[-\\w\\.]*$", + "default": "browser", + "description": "The output directory name of your browser build within the output path base. Defaults to 'browser'." + }, + "server": { + "type": "string", + "pattern": "^[-\\w\\.]*$", + "default": "server", + "description": "The output directory name of your server build within the output path base. Defaults to 'server'." + }, + "media": { + "type": "string", + "pattern": "^[-\\w\\.]+$", + "default": "media", + "description": "The output directory name of your media files within the output browser directory. Defaults to 'media'." + } + }, + "required": ["base"], + "additionalProperties": false + }, + { + "type": "string" + } + ] + }, + "aot": { + "type": "boolean", + "description": "Build using Ahead of Time compilation.", + "x-user-analytics": "ep.ng_aot", + "default": true + }, + "sourceMap": { + "description": "Output source maps for scripts and styles. For more information, see https://angular.dev/reference/configs/workspace-config#source-map-configuration.", + "default": false, + "oneOf": [ + { + "type": "object", + "properties": { + "scripts": { + "type": "boolean", + "description": "Output source maps for all scripts.", + "default": true + }, + "styles": { + "type": "boolean", + "description": "Output source maps for all styles.", + "default": true + }, + "hidden": { + "type": "boolean", + "description": "Output source maps used for error reporting tools.", + "default": false + }, + "vendor": { + "type": "boolean", + "description": "Resolve vendor packages source maps.", + "default": false + }, + "sourcesContent": { + "type": "boolean", + "description": "Output original source content for files within the source map.", + "default": true + } + }, + "additionalProperties": false + }, + { + "type": "boolean" + } + ] + }, + "baseHref": { + "type": "string", + "description": "Base url for the application being built." + }, + "verbose": { + "type": "boolean", + "description": "Adds more details to output logging.", + "default": false + }, + "progress": { + "type": "boolean", + "description": "Log progress to the console while building.", + "default": true + }, + "i18nMissingTranslation": { + "type": "string", + "description": "How to handle missing translations for i18n.", + "enum": ["warning", "error", "ignore"], + "default": "warning" + }, + "i18nDuplicateTranslation": { + "type": "string", + "description": "How to handle duplicate translations for i18n.", + "enum": ["warning", "error", "ignore"], + "default": "warning" + }, + "localize": { + "description": "Translate the bundles in one or more locales.", + "oneOf": [ + { + "type": "boolean", + "description": "Translate all locales." + }, + { + "type": "array", + "description": "List of locales ID's to translate.", + "minItems": 1, + "items": { + "type": "string", + "pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$" + } + } + ] + }, + "watch": { + "type": "boolean", + "description": "Run build when files change.", + "default": false + }, + "outputHashing": { + "type": "string", + "description": "Define the output filename cache-busting hashing mode.\n\n- `none`: No hashing.\n- `all`: Hash for all output bundles. \n- `media`: Hash for all output media (e.g., images, fonts, etc. that are referenced in CSS files).\n- `bundles`: Hash for output of lazy and main bundles.", + "default": "none", + "enum": ["none", "all", "media", "bundles"] + }, + "poll": { + "type": "number", + "description": "Enable and define the file watching poll time period in milliseconds." + }, + "deleteOutputPath": { + "type": "boolean", + "description": "Delete the output path before building.", + "default": true + }, + "preserveSymlinks": { + "type": "boolean", + "description": "Do not use the real path when resolving modules. If unset then will default to `true` if NodeJS option --preserve-symlinks is set." + }, + "extractLicenses": { + "type": "boolean", + "description": "Extract all licenses in a separate file.", + "default": true + }, + "namedChunks": { + "type": "boolean", + "description": "Use file name for lazy loaded chunks.", + "default": false + }, + "subresourceIntegrity": { + "type": "boolean", + "description": "Enables the use of subresource integrity validation.", + "default": false + }, + "serviceWorker": { + "description": "Generates a service worker configuration.", + "default": false, + "oneOf": [ + { + "type": "string", + "description": "Path to ngsw-config.json." + }, + { + "const": false, + "type": "boolean", + "description": "Does not generate a service worker configuration." + } + ] + }, + "index": { + "description": "Configures the generation of the application's HTML index.", + "oneOf": [ + { + "type": "string", + "description": "The path of a file to use for the application's HTML index. The filename of the specified path will be used for the generated file and will be created in the root of the application's configured output path." + }, + { + "type": "object", + "description": "", + "properties": { + "input": { + "type": "string", + "minLength": 1, + "description": "The path of a file to use for the application's generated HTML index." + }, + "output": { + "type": "string", + "minLength": 1, + "default": "index.html", + "description": "The output path of the application's generated HTML index file. The full provided path will be used and will be considered relative to the application's configured output path." + }, + "preloadInitial": { + "type": "boolean", + "default": true, + "description": "Generates 'preload', 'modulepreload', and 'preconnect' link elements for initial application files and resources." + } + }, + "required": ["input"] + }, + { + "const": false, + "type": "boolean", + "description": "Does not generate an `index.html` file." + } + ] + }, + "statsJson": { + "type": "boolean", + "description": "Generates a 'stats.json' file which can be analyzed with https://esbuild.github.io/analyze/.", + "default": false + }, + "budgets": { + "description": "Budget thresholds to ensure parts of your application stay within boundaries which you set.", + "type": "array", + "items": { + "$ref": "#/definitions/budget" + }, + "default": [] + }, + "webWorkerTsConfig": { + "type": "string", + "description": "TypeScript configuration for Web Worker modules." + }, + "crossOrigin": { + "type": "string", + "description": "Define the crossorigin attribute setting of elements that provide CORS support.", + "default": "none", + "enum": ["none", "anonymous", "use-credentials"] + }, + "allowedCommonJsDependencies": { + "description": "A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use `'*'` to allow all.", + "type": "array", + "items": { + "type": "string" + }, + "default": [] + }, + "prerender": { + "description": "Prerender (SSG) pages of your application during build time.", + "oneOf": [ + { + "type": "boolean", + "description": "Enable prerending of pages of your application during build time." + }, + { + "type": "object", + "properties": { + "routesFile": { + "type": "string", + "description": "The path to a file that contains a list of all routes to prerender, separated by newlines. This option is useful if you want to prerender routes with parameterized URLs." + }, + "discoverRoutes": { + "type": "boolean", + "description": "Whether the builder should process the Angular Router configuration to find all unparameterized routes and prerender them.", + "default": true + } + }, + "additionalProperties": false + } + ] + }, + "ssr": { + "description": "Server side render (SSR) pages of your application during runtime.", + "default": false, + "oneOf": [ + { + "type": "boolean", + "description": "Enable the server bundles to be written to disk." + }, + { + "type": "object", + "properties": { + "entry": { + "type": "string", + "description": "The server entry-point that when executed will spawn the web server." + }, + "platform": { + "description": "Specifies the platform for which the server bundle is generated. This affects the APIs and modules available in the server-side code. \n\n- `node`: (Default) Generates a bundle optimized for Node.js environments. \n- `neutral`: Generates a platform-neutral bundle suitable for environments like edge workers, and other serverless platforms. This option avoids using Node.js-specific APIs, making the bundle more portable. \n\nPlease note that this feature does not provide polyfills for Node.js modules.", + "default": "node", + "enum": ["node", "neutral"] + } + }, + "additionalProperties": false + } + ] + }, + "appShell": { + "type": "boolean", + "description": "Generates an application shell during build time." + }, + "outputMode": { + "type": "string", + "description": "Defines the type of build output artifact. 'static': Generates a static site build artifact for deployment on any static hosting service. 'server': Generates a server application build artifact, required for applications using hybrid rendering or APIs.", + "enum": ["static", "server"] + } + }, + "additionalProperties": false, + "required": ["tsConfig"], + "definitions": { + "assetPattern": { + "oneOf": [ + { + "type": "object", + "properties": { + "followSymlinks": { + "type": "boolean", + "default": false, + "description": "Allow glob patterns to follow symlink directories. This allows subdirectories of the symlink to be searched." + }, + "glob": { + "type": "string", + "description": "The pattern to match." + }, + "input": { + "type": "string", + "description": "The input directory path in which to apply 'glob'. Defaults to the project root." + }, + "ignore": { + "description": "An array of globs to ignore.", + "type": "array", + "items": { + "type": "string" + } + }, + "output": { + "type": "string", + "default": "", + "description": "Absolute path within the output." + } + }, + "additionalProperties": false, + "required": ["glob", "input"] + }, + { + "type": "string" + } + ] + }, + "fileReplacement": { + "type": "object", + "properties": { + "replace": { + "type": "string", + "pattern": "\\.(([cm]?[jt])sx?|json)$" + }, + "with": { + "type": "string", + "pattern": "\\.(([cm]?[jt])sx?|json)$" + } + }, + "additionalProperties": false, + "required": ["replace", "with"] + }, + "budget": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "The type of budget.", + "enum": ["all", "allScript", "any", "anyScript", "anyComponentStyle", "bundle", "initial"] + }, + "name": { + "type": "string", + "description": "The name of the bundle." + }, + "baseline": { + "type": "string", + "description": "The baseline size for comparison." + }, + "maximumWarning": { + "type": "string", + "description": "The maximum threshold for warning relative to the baseline." + }, + "maximumError": { + "type": "string", + "description": "The maximum threshold for error relative to the baseline." + }, + "minimumWarning": { + "type": "string", + "description": "The minimum threshold for warning relative to the baseline." + }, + "minimumError": { + "type": "string", + "description": "The minimum threshold for error relative to the baseline." + }, + "warning": { + "type": "string", + "description": "The threshold for warning relative to the baseline (min & max)." + }, + "error": { + "type": "string", + "description": "The threshold for error relative to the baseline (min & max)." + } + }, + "additionalProperties": false, + "required": ["type"] + } + } +} diff --git a/projects/live-preview/builders/src/dev-server/index.ts b/projects/live-preview/builders/src/dev-server/index.ts new file mode 100644 index 0000000000..afa2e5c37b --- /dev/null +++ b/projects/live-preview/builders/src/dev-server/index.ts @@ -0,0 +1,38 @@ +/** + * Copyright (c) Siemens 2016 - 2026 + * SPDX-License-Identifier: MIT + */ +import { createBuilder, targetFromTargetString } from '@angular-devkit/architect'; +import { executeDevServerBuilder, type DevServerBuilderOptions } from '@angular/build'; +import { from } from 'rxjs'; +import { switchMap } from 'rxjs/operators'; + +import { loadPlugins } from '../load-plugins.js'; +import { patchBuilderContext } from './patch-context.js'; + +export default createBuilder( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (options: DevServerBuilderOptions, context: any) => { + const buildTarget = targetFromTargetString(options.buildTarget); + + return from(context.getTargetOptions(buildTarget)).pipe( + switchMap(async buildOptions => { + const pluginPaths = (buildOptions as Record).plugins as + | string[] + | undefined; + const plugins = pluginPaths ? await loadPlugins(pluginPaths, context) : []; + + patchBuilderContext(context, buildTarget); + + return plugins; + }), + switchMap(buildPlugins => { + return executeDevServerBuilder( + options, + context as Parameters[1], + { buildPlugins } + ); + }) + ); + } +); diff --git a/projects/live-preview/builders/src/dev-server/patch-context.ts b/projects/live-preview/builders/src/dev-server/patch-context.ts new file mode 100644 index 0000000000..b37c84dd50 --- /dev/null +++ b/projects/live-preview/builders/src/dev-server/patch-context.ts @@ -0,0 +1,31 @@ +/** + * Copyright (c) Siemens 2016 - 2026 + * SPDX-License-Identifier: MIT + */ +import type { BuilderContext, Target } from '@angular-devkit/architect'; +import type { JsonObject } from '@angular-devkit/core'; + +const BUILDER_REPLACEMENTS: Record = { + '@siemens/angular-builder:application': '@angular/build:application' +}; + +export const patchBuilderContext = (context: BuilderContext, buildTarget: Target): void => { + const originalGetBuilderNameForTarget = context.getBuilderNameForTarget.bind(context); + + context.getBuilderNameForTarget = async (target: Target): Promise => { + const builderName = await originalGetBuilderNameForTarget(target); + return BUILDER_REPLACEMENTS[builderName] ?? builderName; + }; + + const originalGetTargetOptions = context.getTargetOptions.bind(context); + + context.getTargetOptions = async (target: Target): Promise => { + const options = await originalGetTargetOptions(target); + + if (target.project === buildTarget.project && target.target === buildTarget.target) { + delete (options as Record).plugins; + } + + return options; + }; +}; diff --git a/projects/live-preview/builders/src/dev-server/schema.json b/projects/live-preview/builders/src/dev-server/schema.json new file mode 100644 index 0000000000..05106fe49f --- /dev/null +++ b/projects/live-preview/builders/src/dev-server/schema.json @@ -0,0 +1,144 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "title": "Dev Server with esbuild plugin support", + "description": "Dev Server with custom esbuild plugin support. Accepts all options from @angular/build:dev-server.", + "type": "object", + "properties": { + "buildTarget": { + "type": "string", + "description": "A build builder target to serve in the format of `project:target[:configuration]`. You can also pass in more than one configuration name as a comma-separated list. Example: `project:target:production,staging`.", + "pattern": "^[^:\\s]*:[^:\\s]*(:[^\\s]+)?$" + }, + "port": { + "type": "number", + "description": "Port to listen on.", + "default": 4200 + }, + "host": { + "type": "string", + "description": "Host to listen on.", + "default": "localhost" + }, + "proxyConfig": { + "type": "string", + "description": "Proxy configuration file. For more information, see https://angular.dev/tools/cli/serve#proxying-to-a-backend-server." + }, + "ssl": { + "type": "boolean", + "description": "Serve using HTTPS.", + "default": false + }, + "sslKey": { + "type": "string", + "description": "SSL key to use for serving HTTPS." + }, + "sslCert": { + "type": "string", + "description": "SSL certificate to use for serving HTTPS." + }, + "allowedHosts": { + "description": "The hosts that the development server will respond to. This option sets the Vite option of the same name. For further details: https://vite.dev/config/server-options.html#server-allowedhosts", + "default": [], + "oneOf": [ + { + "type": "array", + "description": "A list of hosts that the development server will respond to.", + "items": { + "type": "string" + } + }, + { + "type": "boolean", + "description": "Indicates that all hosts are allowed. This is not recommended and a security risk." + } + ] + }, + "define": { + "description": "Defines global identifiers that will be replaced with a specified constant value when found in any JavaScript or TypeScript code including libraries. The value will be used directly. String values must be put in quotes. Identifiers within Angular metadata such as Component Decorators will not be replaced.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "headers": { + "type": "object", + "description": "Custom HTTP headers to be added to all responses.", + "propertyNames": { + "pattern": "^[-_A-Za-z0-9]+$" + }, + "additionalProperties": { + "type": "string" + } + }, + "open": { + "type": "boolean", + "description": "Opens the url in default browser.", + "default": false, + "alias": "o" + }, + "verbose": { + "type": "boolean", + "description": "Adds more details to output logging." + }, + "liveReload": { + "type": "boolean", + "description": "Whether to reload the page on change, using live-reload.", + "default": true + }, + "servePath": { + "type": "string", + "description": "The pathname where the application will be served." + }, + "hmr": { + "type": "boolean", + "description": "Enable hot module replacement. Defaults to the value of 'liveReload'. Currently, only global and component stylesheets are supported." + }, + "watch": { + "type": "boolean", + "description": "Rebuild on change.", + "default": true + }, + "poll": { + "type": "number", + "description": "Enable and define the file watching poll time period in milliseconds." + }, + "inspect": { + "default": false, + "description": "Activate debugging inspector. This option only has an effect when 'SSR' or 'SSG' are enabled.", + "oneOf": [ + { + "type": "string", + "description": "Activate the inspector on host and port in the format of `[[host:]port]`. See the security warning in https://nodejs.org/docs/latest-v22.x/api/cli.html#warning-binding-inspector-to-a-public-ipport-combination-is-insecure regarding the host parameter usage." + }, + { + "type": "boolean" + } + ] + }, + "prebundle": { + "description": "Enable and control the Vite-based development server's prebundling capabilities. To enable prebundling, the Angular CLI cache must also be enabled.", + "default": true, + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "object", + "properties": { + "exclude": { + "description": "List of package imports that should not be prebundled by the development server. The packages will be bundled into the application code itself. Note: specifying `@foo/bar` marks all paths within the `@foo/bar` package as excluded, including sub-paths like `@foo/bar/baz`.", + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false, + "required": ["exclude"] + } + ] + } + }, + "additionalProperties": false, + "required": ["buildTarget"] +} diff --git a/projects/live-preview/builders/src/index.ts b/projects/live-preview/builders/src/index.ts new file mode 100644 index 0000000000..6347d74cd3 --- /dev/null +++ b/projects/live-preview/builders/src/index.ts @@ -0,0 +1,6 @@ +/** + * Copyright (c) Siemens 2016 - 2026 + * SPDX-License-Identifier: MIT + */ +export { default as applicationBuilder } from './application/index.js'; +export { default as devServerBuilder } from './dev-server/index.js'; diff --git a/projects/live-preview/builders/src/load-plugins.ts b/projects/live-preview/builders/src/load-plugins.ts new file mode 100644 index 0000000000..ba2060ba36 --- /dev/null +++ b/projects/live-preview/builders/src/load-plugins.ts @@ -0,0 +1,56 @@ +/** + * Copyright (c) Siemens 2016 - 2026 + * SPDX-License-Identifier: MIT + */ +import type { BuilderContext } from '@angular-devkit/architect'; +import type { Plugin } from 'esbuild'; +import { resolve, isAbsolute } from 'path'; +import { pathToFileURL } from 'url'; + +export const loadPlugins = async ( + pluginPaths: string[], + context: BuilderContext +): Promise => { + const workspaceRoot = context.workspaceRoot; + const plugins: Plugin[] = []; + + for (const pluginPath of pluginPaths) { + const fullPath = isAbsolute(pluginPath) ? pluginPath : resolve(workspaceRoot, pluginPath); + + try { + const moduleUrl = pathToFileURL(fullPath).href; + const module = await import(moduleUrl); + + let plugin: Plugin | Plugin[] | ((...args: unknown[]) => Plugin | Plugin[]); + + if (module.default) { + plugin = module.default; + } else if (typeof module === 'function') { + plugin = module; + } else { + plugin = module; + } + + if (typeof plugin === 'function') { + const result = plugin(); + if (Array.isArray(result)) { + plugins.push(...result); + } else { + plugins.push(result); + } + } else if (Array.isArray(plugin)) { + plugins.push(...plugin); + } else { + plugins.push(plugin); + } + + context.logger.info(`Loaded esbuild plugin from: ${pluginPath}`); + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error); + context.logger.error(`Failed to load plugin from ${pluginPath}: ${errorMessage}`); + throw new Error(`Failed to load plugin from ${pluginPath}`, { cause: error }); + } + } + + return plugins; +}; diff --git a/projects/live-preview/builders/tsconfig.json b/projects/live-preview/builders/tsconfig.json new file mode 100644 index 0000000000..ab0c2b81c1 --- /dev/null +++ b/projects/live-preview/builders/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "src", + "declaration": false, + "sourceMap": true, + "module": "NodeNext", + "moduleResolution": "NodeNext", + "skipLibCheck": true, + "types": ["node"] + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules", "dist"] +} diff --git a/projects/live-preview/ng-package.json b/projects/live-preview/ng-package.json index a3649dc6af..612dcebcf7 100644 --- a/projects/live-preview/ng-package.json +++ b/projects/live-preview/ng-package.json @@ -2,7 +2,14 @@ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", "dest": "../../dist/@siemens/live-preview", "allowedNonPeerDependencies": ["."], - "assets": ["./assets", "component-loader.cjs", "esbuild-component-loader.mjs", "styles"], + "assets": [ + "./assets", + "component-loader.cjs", + "esbuild-component-loader.mjs", + "styles", + "builders.json", + "builders/dist" + ], "lib": { "entryFile": "./public-api.ts" } diff --git a/projects/live-preview/package.json b/projects/live-preview/package.json index 4219f379e0..ec5c3f0f58 100644 --- a/projects/live-preview/package.json +++ b/projects/live-preview/package.json @@ -17,6 +17,7 @@ "publishConfig": { "access": "public" }, + "builders": "./builders.json", "dependencies": { "@stackblitz/sdk": "^1.11.0", "codeflask": "^1.4.1", @@ -57,6 +58,9 @@ } }, "exports": { + "./package.json": { + "default": "./package.json" + }, "./component-loader": { "default": "./component-loader.cjs" },