Skip to content

perf: require rspack to improve startup performance#5673

Merged
chenjiahan merged 1 commit intomainfrom
require_rspack_0725
Jul 25, 2025
Merged

perf: require rspack to improve startup performance#5673
chenjiahan merged 1 commit intomainfrom
require_rspack_0725

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

@chenjiahan chenjiahan commented Jul 25, 2025

Summary

Currently, Rspack only provides a CJS bundle, so we use require to load it for better startup performance. If we use import { rspack } from '@rspack/core', Node.js will use cjs-module-lexer to parse it, which slows down startup by 25-30ms.

We can remove this module once @rspack/core provides an ESM bundle in the future.

Before

After

Related Links

Checklist

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

Copilot AI review requested due to automatic review settings July 25, 2025 06:26
@netlify
Copy link
Copy Markdown

netlify bot commented Jul 25, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit d036550
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/6883239b225b450008d64bd1
😎 Deploy Preview https://deploy-preview-5673--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: 83 (🟢 up 7 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 improves startup performance by replacing direct ES module imports of @rspack/core with a CommonJS require approach. The change addresses a ~30ms startup delay caused by Node.js's cjs-module-lexer when importing from the CJS-only Rspack bundle.

Key changes:

  • Created a new rspack.ts module that uses createRequire to load Rspack via CommonJS
  • Updated all files to import rspack from the new module instead of directly from @rspack/core
  • Modified plugin files to receive rspack from the bundler chain context instead of importing it

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/core/src/rspack.ts New module providing CommonJS-based Rspack import for performance
packages/core/src/server/devMiddlewares.ts Updated to use centralized rspack import
packages/core/src/provider/rspackConfig.ts Updated to use centralized rspack import
packages/core/src/provider/createCompiler.ts Updated to use centralized rspack import
packages/core/src/provider/build.ts Updated to use centralized rspack import
packages/core/src/plugins/sri.ts Updated to receive rspack from chain context
packages/core/src/plugins/rspackProfile.ts Updated to use centralized rspack import
packages/core/src/plugins/progress.ts Updated to receive rspack from chain context
packages/core/src/plugins/output.ts Updated to receive rspack from chain context
packages/core/src/plugins/moduleFederation.ts Updated to use centralized rspack import
packages/core/src/plugins/minimize.ts Updated to receive rspack from chain context
packages/core/src/pluginHelper.ts Updated to use centralized rspack import
packages/core/src/index.ts Updated to use centralized rspack import
Comments suppressed due to low confidence (1)

packages/core/src/rspack.ts:10

  • The variable name rspack on line 10 shadows the exported rspack on line 13, which could be confusing. Consider renaming the internal variable to rspackModule or rspackCore for clarity.
const rspack =

@chenjiahan chenjiahan changed the title perf: require rspack for improved startup performance perf: require rspack to improve startup performance Jul 25, 2025
@chenjiahan chenjiahan merged commit cdbed36 into main Jul 25, 2025
15 checks passed
@chenjiahan chenjiahan deleted the require_rspack_0725 branch July 25, 2025 06:35
@chenjiahan chenjiahan mentioned this pull request Jul 26, 2025
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