dev.setupMiddlewares

    • Type:
    type SetupMiddlewaresServer = {
      sockWrite: (
        type: string,
        data?: string | boolean | Record<string, any>,
      ) => void;
      environments: {
        [name: string]: {
          /**
           * Get stats info about current environment.
           */
          getStats: () => Promise<Stats>;
          /**
           * Load and execute stats bundle in server.
           *
           * @param entryName - relate to Rsbuild's `source.entry`
           * @returns the return value of entry module.
           */
          loadBundle: <T = unknown>(entryName: string) => Promise<T>;
    
          /**
           * Get the compiled HTML template.
           */
          getTransformedHtml: (entryName: string) => Promise<string>;
        };
      };
    };
    
    type SetupMiddlewares = Array<
      (
        middlewares: {
          unshift: (...handlers: RequestHandler[]) => void;
          push: (...handlers: RequestHandler[]) => void;
        },
        server: SetupMiddlewaresServer,
      ) => void
    >;
    • Default: undefined

    Provides the ability to execute a custom function and apply custom middlewares.

    INFO

    The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to Rsbuild - dev.setupMiddlewares.