perf: remove pre-bundling of postcss-load-config#5808
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the build process by removing pre-bundling of postcss-load-config and instead importing it directly, which reduces Node.js import overhead by bundling it into the main bundle.
Key Changes:
- Replaced dynamic import of pre-bundled
postcss-load-configwith direct import - Updated error handling to use proper type assertion for the caught error
- Added
yamlas an external dependency since it's an optional dependency ofpostcss-load-config
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/plugins/css.ts | Replaced dynamic import with direct import and improved error type handling |
| packages/core/rslib.config.ts | Added yaml as external dependency to handle optional dependency |
| packages/core/prebundle.config.mjs | Removed entire pre-bundling configuration for postcss-load-config |
| const promise = postcssrc({}, root).catch((err: unknown) => { | ||
| // ignore the config not found error | ||
| if (err.message?.includes('No PostCSS Config found')) { | ||
| if ((err as Error).message?.includes('No PostCSS Config found')) { |
There was a problem hiding this comment.
The parameter type changed from Error to unknown, but the catch block still assumes it's an Error. Consider using a type guard or keeping the Error type if you're confident postcssrc only throws Error instances.
| if ((err as Error).message?.includes('No PostCSS Config found')) { | |
| if ( | |
| typeof err === 'object' && | |
| err !== null && | |
| 'message' in err && | |
| typeof (err as { message?: unknown }).message === 'string' && | |
| (err as { message: string }).message.includes('No PostCSS Config found') | |
| ) { |
| const promise = postcssrc({}, root).catch((err: unknown) => { | ||
| // ignore the config not found error | ||
| if (err.message?.includes('No PostCSS Config found')) { | ||
| if ((err as Error).message?.includes('No PostCSS Config found')) { |
There was a problem hiding this comment.
Using type assertion (err as Error) without validation can be unsafe. Consider using a type guard like err instanceof Error before accessing the message property.
| if ((err as Error).message?.includes('No PostCSS Config found')) { | |
| if (err instanceof Error && err.message?.includes('No PostCSS Config found')) { |

Summary
Since
postcss-load-configis required to be executed by default, we don't need to pre-bundle it. Using Rslib to bundle it directly into the main bundle can reduce the overhead of Node.js import.Checklist