Skip to content

Revert "fix(type): make the PostCSS plugin type loose (#5364)" #5366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
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
8 changes: 3 additions & 5 deletions packages/core/src/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ const getPostcssLoaderOptions = async ({
root: string;
postcssrcCache: PostcssrcCache;
}): Promise<PostCSSLoaderOptions> => {
const extraPlugins: unknown[] = [];
const extraPlugins: AcceptedPlugin[] = [];

const utils = {
addPlugins(plugins: unknown | unknown[]) {
addPlugins(plugins: AcceptedPlugin | AcceptedPlugin[]) {
extraPlugins.push(...castArray(plugins));
},
};
Expand Down Expand Up @@ -181,9 +181,7 @@ const getPostcssLoaderOptions = async ({
// initialize the plugin to avoid multiple initialization
// https://github.com/web-infra-dev/rsbuild/issues/3618
options.plugins = options.plugins.map((plugin) =>
isPostcssPluginCreator(plugin as AcceptedPlugin)
? (plugin as PluginCreator<unknown>)()
: plugin,
isPostcssPluginCreator(plugin) ? plugin() : plugin,
);

// always use postcss-load-config to load external config
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import type {
CSSLoaderOptions,
HtmlRspackPlugin,
PostCSSLoaderOptions,
PostCSSPlugin,
StyleLoaderOptions,
WebpackConfig,
} from './thirdParty';
Expand All @@ -60,7 +61,7 @@ export type ToolsBundlerChainConfig = OneOrMany<

export type ToolsPostCSSLoaderConfig = ConfigChainWithContext<
PostCSSLoaderOptions,
{ addPlugins: (plugins: unknown | unknown[]) => void }
{ addPlugins: (plugins: PostCSSPlugin | PostCSSPlugin[]) => void }
>;

export type ToolsCSSLoaderConfig = ConfigChain<CSSLoaderOptions>;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/thirdParty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type { WebpackConfig };

export type PostCSSOptions = ProcessOptions & {
config?: boolean;
plugins?: unknown[];
plugins?: AcceptedPlugin[];
};

export type PostCSSLoaderOptions = {
Expand Down
Loading