diff --git a/packages/rspack/src/utils/with-react.ts b/packages/rspack/src/utils/with-react.ts index 6afd0974c..b3d0dc9cd 100644 --- a/packages/rspack/src/utils/with-react.ts +++ b/packages/rspack/src/utils/with-react.ts @@ -1,8 +1,10 @@ import { Configuration } from '@rspack/core'; import { SharedConfigContext } from './model'; -import { withWeb } from './with-web'; +import { withWeb, WithWebOptions } from './with-web'; -export function withReact(opts = {}) { +export type WithReactOptions = Omit; + +export function withReact(opts:WithWebOptions = {}) { return function makeConfig( config: Configuration, { options, context }: SharedConfigContext diff --git a/packages/rspack/src/utils/with-web.ts b/packages/rspack/src/utils/with-web.ts index 1d735a4d5..cb1004428 100644 --- a/packages/rspack/src/utils/with-web.ts +++ b/packages/rspack/src/utils/with-web.ts @@ -7,6 +7,7 @@ export interface WithWebOptions { includePaths?: string[]; }; cssModules?: boolean; + htmlPlugins?: false | Configuration['plugins']; } export function withWeb(opts: WithWebOptions = {}) { @@ -112,11 +113,21 @@ export function withWeb(opts: WithWebOptions = {}) { }, plugins: [ ...config.plugins, - new rspack.HtmlRspackPlugin({ - template: options.indexHtml - ? path.join(context.root, options.indexHtml) - : path.join(projectRoot, 'src/index.html'), - }), + ...(() => { + if (opts.htmlPlugins === false) { + return []; + } + if (opts.htmlPlugins) { + return opts.htmlPlugins; + } + return [ + new rspack.HtmlRspackPlugin({ + template: options.indexHtml + ? path.join(context.root, options.indexHtml) + : path.join(projectRoot, 'src/index.html'), + }), + ]; + })(), new rspack.DefinePlugin({ 'process.env.NODE_ENV': isProd ? "'production'" : "'development'", }),