Skip to content

rename-build-artifact work in progress ​

A build helper from @frontpack/widget-build-tools that renames the Angular application builder's main.js output to a stable, consumer-chosen bundle name.

Do you need this? ​

  • ✅ Your widget is built with the Angular application builder and needs a predictable, stable bundle filename (e.g. nsweb-station-list.widget.js) for the host to load.
  • ❌ Skip this if your build already supports a custom entry filename natively (e.g. via a bundler config option).

What problem does it solve? ​

The Angular application builder always names its single browser entry point output main.js, with no supported option to rename it. Micro-frontend widgets, however, need a stable, predictable bundle filename so the host application can reference it (see naming conventions) — main.js is both unpredictable (every widget would collide on the same name) and not descriptive.

This tool renames the built main.js (and its main.js.map, if present) to a name you choose, after the Angular build runs.

How to install it ​

bash
npm install --save-dev @frontpack/widget-build-tools

How to use it ​

For usage in CI ​

Run it as a CLI step after your Angular build, pointing it at the build's output directory:

bash
npx widget-rename-build-artifact --output-dir dist/packages/my-widget/browser --to my-widget.widget
FlagRequiredDescription
--output-diryesDirectory containing the build output (the Angular browser output dir).
--toyesDesired artifact base name, without extension.
--fromnoCurrent artifact base name, without extension. Defaults to main.

For usage in Nx environment ​

Split the Angular build into its own target, then chain it with the rename step in a nx:run-commands target so nx build my-widget runs both in order:

json
// packages/my-widget/project.json
{
  "targets": {
    "build-angular": {
      "executor": "@angular/build:application",
      "options": {
        "outputPath": "dist/packages/my-widget",
        "browser": "packages/my-widget/src/main.ts"
      }
    },
    "build": {
      "executor": "nx:run-commands",
      "outputs": ["{workspaceRoot}/dist/packages/my-widget"],
      "options": {
        "commands": ["nx run my-widget:build-angular", "node_modules/.bin/widget-rename-build-artifact --output-dir dist/packages/my-widget/browser --to my-widget.widget"],
        "parallel": false
      }
    }
  }
}

TIP

parallel: false is required — the rename step must run strictly after build-angular finishes, not alongside it.

For programmatical usage ​

You can also call it programmatically from a Node script, via the @frontpack/widget-build-tools/rename-build-artifact entry point:

ts
import { renameBuildArtifact } from '@frontpack/widget-build-tools/rename-build-artifact';

renameBuildArtifact({
  outputDir: 'dist/packages/my-widget/browser',
  to: 'my-widget.widget',
});