Skip to content

perf(@angular/cli): fix unnecessary esbuild rebuilds #30234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sirTomasson
Copy link
Contributor

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

When using esbuild, Angular sets up a custom file watcher using esbuilds metafile inputs. Esbuild will generate define:KEY entries see https://esbuild.github.io/try/#YgAwLjI1LjMALS1kZWZpbmU6Rk9PPSd7fScgLS1tZXRhZmlsZSAtLWJ1bmRsZQBlAGVudHJ5LmpzAGNvbnNvbGUubG9nKEZPTyk. After the build is finished, the file watcher will notice that the define:KEY entries no longer exist on the file system and trigger a rebuild even though no files have changed.

Issue Number: N/A

What is the new behavior?

No rebuilds are triggered since the file watcher is no longer tracking changes to define:KEY entries.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

There other conditions which may also trigger a rebuilds, because the file watcher is tracking all inputs from the metafile, which are not necessarily files. This esbuild plugin example will also trigger a rebuild because esbuild will add the ns-env namespace to the metafile inputs.

Copy link

google-cla bot commented May 2, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@angular-robot angular-robot bot added area: performance Issues related to performance area: @angular/cli labels May 2, 2025
@sirTomasson sirTomasson changed the base branch from main to 19.2.x May 2, 2025 14:16
@sirTomasson sirTomasson changed the base branch from 19.2.x to main May 2, 2025 14:16
Copy link
Member

@clydin clydin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the scope to be @angular/build instead of @angular/cli?

Otherwise, LGTM.

Thank you for the contribution.

@clydin clydin added the target: patch This PR is targeted for the next patch release label May 2, 2025
When using esbuild, Angular sets up a custom file watcher using esbuilds metafile inputs. Esbuild will generate <define:KEY> entries see https://esbuild.github.io/try/#YgAwLjI1LjMALS1kZWZpbmU6Rk9PPSd7fScgLS1tZXRhZmlsZSAtLWJ1bmRsZQBlAGVudHJ5LmpzAGNvbnNvbGUubG9nKEZPTyk. After the build is finished, the file watcher will notice that the <define:KEY> entries no longer exist on the file system and trigger a rebuild even though no files have changed.
This change, fixes the above issue by filtering files starting with `<define:`.
@sirTomasson sirTomasson force-pushed the perf-unnecessary-esbuld-rebuilds branch from b4bfb44 to 85dc594 Compare May 3, 2025 08:53
@sirTomasson
Copy link
Contributor Author

I changed the scope to @angular/build.

@jkrems jkrems added the action: merge The PR is ready for merge by the caretaker label May 3, 2025
@jkrems jkrems merged commit f73e3a3 into angular:main May 3, 2025
32 checks passed
@jkrems
Copy link
Contributor

jkrems commented May 3, 2025

The changes were merged into the following branches: main, 19.2.x, 20.0.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: @angular/build area: @angular/cli area: performance Issues related to performance target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants