Skip to content

Feature request: expose CustomWebpackSchema options to indexTransform #2419

Open

Description

@tonyliving

It would be useful if the custom index HTML transform received the active CustomWebpackSchema options in addition to target and indexHtml.

Currently, the transform is called as follows:

return transform(target, indexHtml);

I propose changing it to:

return transform(target, indexHtml, options);

Current behavior

An indexTransform can access:

The Angular builder target
The generated index HTML

However, it cannot directly access the normalized options passed to the custom webpack builder.

Proposed behavior

Update the transform invocation in indexHtmlTransformFactory:

export const indexHtmlTransformFactory: (
  options: CustomWebpackSchema,
  context: BuilderContext
) => IndexHtmlTransform = (options, { workspaceRoot, target, logger }) => {
  if (!options.indexTransform) return null;

  const transformPath = path.join(
    getSystemPath(normalize(workspaceRoot)),
    options.indexTransform
  );
  const tsConfig = path.join(
    getSystemPath(normalize(workspaceRoot)),
    options.tsConfig
  );

  return async (indexHtml: string) => {
    const transform = await loadModule<IndexHtmlTransformWithOptions>(
      transformPath,
      tsConfig,
      logger
    );

    return transform(target, indexHtml, options);
  };
};

Use case

My index transform needs to generate different HTML depending on the active custom webpack builder options.

Backward compatibility

This change should be backward-compatible at runtime because existing transforms can continue accepting only two arguments:

The additional argument will simply be ignored by existing JavaScript functions.

Making the third TypeScript parameter optional would also help preserve compatibility for existing typed transforms.

I would like to request this enhancement specifically for the release/v22 branch

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions