Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/rspack/src/utils/with-react.ts
Original file line number Diff line number Diff line change
@@ -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<WithWebOptions, 'cssModules'>;

export function withReact(opts:WithWebOptions = {}) {
return function makeConfig(
config: Configuration,
{ options, context }: SharedConfigContext
Expand Down
21 changes: 16 additions & 5 deletions packages/rspack/src/utils/with-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface WithWebOptions {
includePaths?: string[];
};
cssModules?: boolean;
htmlPlugins?: false | Configuration['plugins'];
}

export function withWeb(opts: WithWebOptions = {}) {
Expand Down Expand Up @@ -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'",
}),
Expand Down