Skip to content

perf: remove pre-bundling of postcss-load-config#5808

Merged
chenjiahan merged 2 commits intomainfrom
pre_bundle_update_0810
Aug 10, 2025
Merged

perf: remove pre-bundling of postcss-load-config#5808
chenjiahan merged 2 commits intomainfrom
pre_bundle_update_0810

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

Since postcss-load-config is 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

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings August 10, 2025 11:24
@netlify
Copy link
Copy Markdown

netlify bot commented Aug 10, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit fb8e44e
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/689882ac5fba260008a6fac0
😎 Deploy Preview https://deploy-preview-5808--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 66 (🟢 up 1 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-config with direct import
  • Updated error handling to use proper type assertion for the caught error
  • Added yaml as an external dependency since it's an optional dependency of postcss-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')) {
Copy link

Copilot AI Aug 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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')
) {

Copilot uses AI. Check for mistakes.
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')) {
Copy link

Copilot AI Aug 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if ((err as Error).message?.includes('No PostCSS Config found')) {
if (err instanceof Error && err.message?.includes('No PostCSS Config found')) {

Copilot uses AI. Check for mistakes.
@chenjiahan chenjiahan merged commit 3887ff2 into main Aug 10, 2025
11 checks passed
@chenjiahan chenjiahan deleted the pre_bundle_update_0810 branch August 10, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants