UNPKG

@esmx/rspack

Version:

A high-performance Rspack integration for Esmx microfrontend framework, providing Module Linking and SSR capabilities.

169 lines (168 loc) 4.87 kB
import type { Esmx } from '@esmx/core'; import { type SwcLoaderOptions } from '@rspack/core'; import { type BuildTarget, RSPACK_LOADER, type RspackAppOptions } from '../rspack'; import type { TargetSetting } from './target-setting'; export type { TargetSetting }; export interface RspackHtmlAppOptions extends RspackAppOptions { /** * CSS output mode configuration * * @default Automatically selected based on environment: * - Production: 'css', outputs CSS to separate files for better caching and parallel loading * - Development: 'js', bundles CSS into JS to support hot module replacement (HMR) for instant style updates * * - 'css': Output CSS to separate CSS files * - 'js': Bundle CSS into JS files and dynamically inject styles at runtime * - false: Disable default CSS processing configuration, requires manual loader rule configuration * * @example * ```ts * // Use environment default configuration * css: undefined * * // Force output to separate CSS files * css: 'css' * * // Force bundle into JS * css: 'js' * * // Custom CSS processing * css: false * ``` */ css?: 'css' | 'js' | false; /** * Custom loader configuration * * Allows replacing default loader implementations, useful for switching to framework-specific loaders * * @example * ```ts * // Use Vue's style-loader * loaders: { * styleLoader: 'vue-style-loader' * } * ``` */ loaders?: Partial<Record<keyof typeof RSPACK_LOADER, string>>; /** * Configure style injection method. For complete options, see: * https://github.com/webpack-contrib/style-loader * * @example * ```ts * styleLoader: { * injectType: 'singletonStyleTag', * attributes: { id: 'app-styles' } * } * ``` */ styleLoader?: Record<string, any>; /** * Configure CSS modules, URL resolution, etc. For complete options, see: * https://github.com/webpack-contrib/css-loader * * @example * ```ts * cssLoader: { * modules: true, * url: false * } * ``` */ cssLoader?: Record<string, any>; /** * Configure Less compilation options. For complete options, see: * https://github.com/webpack-contrib/less-loader * * @example * ```ts * lessLoader: { * lessOptions: { * javascriptEnabled: true, * modifyVars: { '@primary-color': '#1DA57A' } * } * } * ``` */ lessLoader?: Record<string, any>; /** * Automatically inject global style resources. For complete options, see: * https://github.com/yenshih/style-resources-loader * * @example * ```ts * styleResourcesLoader: { * patterns: [ * './src/styles/variables.less', * './src/styles/mixins.less' * ] * } * ``` */ styleResourcesLoader?: Record<string, any>; /** * Configure TypeScript/JavaScript compilation options. For complete options, see: * https://rspack.dev/guide/features/builtin-swc-loader * * @example * ```ts * swcLoader: { * jsc: { * parser: { * syntax: 'typescript', * decorators: true * }, * transform: { * legacyDecorator: true * } * } * } * ``` */ swcLoader?: SwcLoaderOptions; /** * Define compile-time global constants, supports setting different values for different build targets * For complete documentation, see: https://rspack.dev/plugins/webpack/define-plugin * * @example * ```ts * // Unified value * definePlugin: { * 'process.env.APP_ENV': JSON.stringify('production') * } * * // Values for different build targets * definePlugin: { * 'process.env.IS_SERVER': { * server: 'true', * client: 'false' * } * } * ``` */ definePlugin?: Record<string, string | Partial<Record<BuildTarget, string>>>; /** * Set the target runtime environment for the code, affecting code compilation downgrading and polyfill injection * * @example * ```ts * // Global compatible mode * target: 'compatible' * * // Global modern mode * target: 'modern' * * // Global custom targets * target: ['chrome>=89', 'edge>=89', 'firefox>=108', 'safari>=16.4', 'node>=24'] * * // Per-build-target configuration * target: { * client: 'modern', * server: ['node>=24'] * } * ``` */ target?: TargetSetting; } export declare function createRspackHtmlApp(esmx: Esmx, options?: RspackHtmlAppOptions): Promise<import("@esmx/core").App>;