GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Needs extra support in build process for other types of service-workers · Issue #29501 · angular/angular-cli

Needs extra support in build process for other types of service-workers #29501

New issue
Copy link
New issue
Copy link
Closed as duplicate
Enhancement
Closed as duplicate
Needs extra support in build process for other types of service-workers#29501
Enhancement
Copy link
Labels
area: @angular/build

Description

@OysteinAmundsen
OysteinAmundsen
opened on Jan 28, 2025
Issue body actions

Command

serve, build

Description

Angular has great support for its own @angular/pwa today. It works as it should, but does not provide much in form of extensibility. You can configure it to do most things, but you do not have full control over the code. This is why we want to use workbox instead.

We can build workbox into our application from a production build, but this is cumbersome when developing the service-worker and we want to test features and functionality frequently. Then you have a code, compile, wait, test cycle which takes a lot of time. We want to be able to serve our service-worker using the built in vite dev-server in angular, like we can for @angular/pwa service-workers.

Someone suggested using a custom esbuilder for this. I found two alternative builders which allow for esbuild plugins to be injected into the build process: @angular-builders/custom-esbuild:application or @nx/angular:application. But they seem to be executing too soon and do not have access to all files nescessary to build up a proper manifest of all the output files from the build process.

So I disected the build and the serve flow in angular-cli, in order to see how we could extend the build process with our needs:

ng build

When we run ng build, the following code is invoked:

@angular-devkit:application
  -> @angular/build:application
    -> angular-cli/packages/angular/build/src/builders/application
      -> buildApplication
        -> buildApplicationInternal

ng serve

@angular-devkit:dev-server
  -> angular-cli/packages/angular_devkit/build_angular/src/builders/dev-server
    -> angular-cli/packages/angular_devkit/build/src/builders/dev-server/builder.ts
      -> @angular/build/private
        -> angular-cli/packages/angular/build/src/private.ts
          -> buildApplicationInternal

We see that buildApplicationInternal is used in both cases, and this function returns a result.files property containing all the output from the build. Great! Exactly what we need.

Now the result object here is created by running executeBuild which builds the application. And one of the functions it executes, is executePostBundleStep which in turn builds the @angular/pwa service worker using augmentAppwithServiceWorkerEsbuild. This function receives all the outputFiles, assetFiles and the index html file and builds up the service worker.

Describe the solution you'd like

We need to be able to execute a function at the same spot and with the same type of input at you are giving the augmentAppWithServiceWorkerEsbuild function.

My suggestion is this:
Allow a postBundleScript: string in your options, pointing to a file in the project. This will allow devs to add a function which gets a callback before or after the point where you build angular sw today.

Example of such a function:

export default function postBundle(
	workspaceRoot,
	baseHref,
	indexHtmlOutput,
	outputFiles,
	assetFiles
) {
	// Whatever logic users need to perform at this point
}

Describe alternatives you've considered

We've tried to add our own custom builder, but the results from executeBuild is not exposed to other build steps. Exposing those in the results from other builders would of course also be a potential solution.
Today the result from other builders is always only { success: true }.

Activity

  1. alan-agius4
    added
    featureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
    area: @angular/build
    and removed
    featureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
    on Jan 29, 2025
  2. alan-agius4 commented on Jan 29, 2025

    @alan-agius4
    alan-agius4
    on Jan 29, 2025
    Collaborator
    More actions

    This is pretty much the same feature request as #11787

  3. alan-agius4
    closed this as a duplicateof Build process hook #11787 on Jan 29, 2025
  4. angular-automatic-lock-bot commented on Mar 1, 2025

    @angular-automatic-lock-bot
    angular-automatic-lock-botBot
    on Mar 1, 2025
    More actions

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. angular-automatic-lock-bot
    locked and limited conversation to collaborators on Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: @angular/build

    Type

    Enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.