Skip to content

Conversation

@chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented May 9, 2025

Summary

This PR adds a new callerName option to createRsbuild to specify the name of the framework or tool that is currently invoking Rsbuild, which can be accessed by Rsbuild plugins through context.callerName, and execute different logic based on this identifier.

This naming is inspired by the caller.name option provided by Babel.

import { myPlugin } from './myPlugin';

const rsbuild = await createRsbuild({
  callerName: 'rslib',
  rsbuildConfig: {
    plugins: [myPlugin],
  },
});
// myPlugin.ts
export const myPlugin = {
  name: 'my-plugin',
  setup(api) {
    const { callerName } = api.context;

    if (callerName === 'rslib') {
      // ...
    } else if (callerName === 'rsbuild') {
      // ...
    }
  },
};

Checklist

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

@netlify
Copy link

netlify bot commented May 9, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 2d008e2
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/681d9e80ef6f51000852cf81
😎 Deploy Preview https://deploy-preview-5204--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 12 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 site configuration.

Copy link
Contributor

@Timeless0911 Timeless0911 left a comment

Choose a reason for hiding this comment

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

LGTM

@chenjiahan chenjiahan merged commit 2b3f2e3 into main May 9, 2025
13 checks passed
@chenjiahan chenjiahan deleted the caller_name_0509 branch May 9, 2025 06:37
@chenjiahan chenjiahan mentioned this pull request May 9, 2025
colinaaa added a commit to lynx-family/lynx-stack that referenced this pull request May 10, 2025
## Summary

Set the `callerName` option of `createRsbuild`, which can be accessed by
Rsbuild plugins through `api.context.callerName`.

See:

- web-infra-dev/rsbuild#5204
- web-infra-dev/rslib#974

## Checklist

<!--- Check and mark with an "x" -->

- [x] Tests updated (or not required).
- [x] Documentation updated (or not required).
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