Skip to content

Enable index transformer #104

Closed
Closed
@vz-tl

Description

@vz-tl
Contributor

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),

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Coly010@vz-tl

      Issue actions

        Enable index transformer · Issue #104 · nrwl/angular-rspack