Skip to content

Enable index transformer #104

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

Open
vz-tl opened this issue Jun 3, 2025 · 1 comment · May be fixed by #118
Open

Enable index transformer #104

vz-tl opened this issue Jun 3, 2025 · 1 comment · May be fixed by #118
Labels

Comments

@vz-tl
Copy link

vz-tl commented Jun 3, 2025

I noticed that the option for transforming index.html is already prepared but not finalized, however it apparently doesn't require a lot to make that work.

So I'd highly appreciate if this feature could be added to the plug-in soon!

For the meanwhile I temporarily added the functionality by monkey-patching the plugin package:

--- a/node_modules/@nx/angular-rspack/dist/lib/models/angular-rspack-plugin-options.d.ts
+++ b/node_modules/@nx/angular-rspack/dist/lib/models/angular-rspack-plugin-options.d.ts
@@ -138,12 +138,11 @@ export type IndexExpandedDefinition = {
     input: string;
     output?: string;
     preloadInitial?: boolean;
+    transformer?: IndexHtmlTransform;
 };
 export type IndexElement = IndexExpandedDefinition | string | false;
 export type IndexHtmlTransform = (content: string) => Promise<string>;
-export type NormalizedIndexElement = IndexExpandedDefinition & {
-    transformer: IndexHtmlTransform | undefined;
-};
+export type NormalizedIndexElement = IndexExpandedDefinition;
 export type NormalizedEntryPoint = Required<Exclude<ScriptOrStyleEntry, string>>;
 export interface SourceMap {
     scripts: boolean;
--- a/node_modules/@nx/angular-rspack/dist/lib/models/normalize-options.js
+++ b/node_modules/@nx/angular-rspack/dist/lib/models/normalize-options.js
@@ -126,8 +126,7 @@ async function normalizeOptions(options) {
     const index = {
         input: (0, node_path_1.resolve)(root, typeof options.index === 'string' ? options.index : options.index.input),
         output: indexOutput,
-        // @TODO: Add support for transformer
-        transformer: undefined,
+        transformer: typeof options.index === 'object' ? options.index.transformer : undefined,
         // Preload initial defaults to true
         preloadInitial: typeof options.index !== 'object' ||
             (options.index.preloadInitial ?? true),
--- a/node_modules/@nx/angular-rspack/dist/lib/plugins/ng-rspack.js
+++ b/node_modules/@nx/angular-rspack/dist/lib/plugins/ng-rspack.js
@@ -97,6 +97,7 @@ class NgRspackPlugin {
                 entrypoints: (0, entry_points_1.getEntryPoints)(this.pluginOptions.globalStyles, this.pluginOptions.globalScripts, this.pluginOptions.devServer?.hmr),
                 i18n: this.i18n,
                 optimization: this.pluginOptions.optimization,
+                postTransform: this.pluginOptions.index.transformer,
                 isSsr: !!(this.pluginOptions.ssr ||
                     this.pluginOptions.prerender ||
                     this.pluginOptions.appShell),
@Coly010
Copy link
Collaborator

Coly010 commented Jun 9, 2025

Feel free to open a PR :)

@vz-tl vz-tl linked a pull request Jun 11, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants