Skip to content
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

TargetOptions parameter is not there with custom-esbuild #1690

Open
shisukei opened this issue Feb 23, 2024 · 2 comments · May be fixed by #1705
Open

TargetOptions parameter is not there with custom-esbuild #1690

shisukei opened this issue Feb 23, 2024 · 2 comments · May be fixed by #1705
Labels
bug Something isn't working

Comments

@shisukei
Copy link

Describe the Bug

Hi,

I am currently working on upgrading an Angular 16 application to Angular 17 and I would like to use esbuild.
My application requires index.html transformation. This transformation relies on data from the targetOptions parameter.

With version 16, I was using @angular-builders/custom-webpack and it was working fine.
Unfortunately, with @angular-builders/custom-esbuild, the targetOptions are not present during the transformation. Instead, it's the content of the index file.
Yet the documentation indicates that targetOptions should be accessible.

Minimal Reproduction

Just creating a new Angular 17 application (via ng new), and following the instruction of the doc :

  • Adding @angular-builders/custom-esbuild as a dev dependency
  • Replacing @angular-devkit/build-angular:application with @angular-builders/custom-esbuild:application and @angular-devkit/build-angular:dev-server with @angular-builders/custom-esbuild:dev-server in angular.json
  • Adding index-html-transformer.ts with the following code :
import { Target } from '@angular-devkit/architect/src/input-schema';
import { json } from '@angular-devkit/core';

type TargetOptions = json.JsonObject & Target;

export default (targetOptions: TargetOptions, indexHtml: string) => {
  console.log('targetOptions', targetOptions);

  const i = indexHtml.indexOf('</body>');
  const config = `<p>Configuration: ${targetOptions.configuration}</p>`;
  return `${indexHtml.slice(0, i)}
            ${config}
            ${indexHtml.slice(i)}`;
};
  • Adding indexHtmlTransformer in angular.json

Here is the result on ng build / ng serve :

custom esbuild ko

Expected Behavior

TargetOptions should be there. Or at least, documentation needs an update.

Environment


Libs
- @angular/core version: 17.2.0
- @angular-devkit/build-angular version: 17.2.1
- @angular-builders/custom-esbuild: 17.1.0

For Tooling issues:
- Node version: 20.11.1
- Platform: Windows
@shisukei shisukei changed the title TargetOptions parameter is undefined with custom-esbuild TargetOptions parameter is not there with custom-esbuild Feb 23, 2024
@just-jeb just-jeb added the bug Something isn't working label Feb 24, 2024
@cristiandeschamps
Copy link

I just got the same error and the arguments seem to have change.

The 1st argument should be indexHtml: string, but get nothing from the 2nd argument (targetOptions).

@Delagen
Copy link

Delagen commented May 20, 2024

Seems packages/custom-esbuild/src/application/index.ts::30 should be something like

return { codePlugins, indexHtmlTransformer: indexHtmlTransformer?.bind(null, options) } as ApplicationBuilderExtensions;

But options param seems only contain target options, not configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants