Skip to content

feat: add transform-imports plugin#51

Merged
sapphi-red merged 6 commits intomainfrom
feat/add-transform-imports-plugin
Apr 20, 2026
Merged

feat: add transform-imports plugin#51
sapphi-red merged 6 commits intomainfrom
feat/add-transform-imports-plugin

Conversation

@sapphi-red
Copy link
Copy Markdown
Member

@sapphi-red sapphi-red commented Apr 8, 2026

This PR adds @rolldown/plugin-transform-imports which utilizes Rolldown's native magic string feature.

In the synthetic benchmark included in this PR, this plugin is

  • 1.36x faster than using @swc/plugin-transform-imports + @rollup/plugin-swc
  • 2.91x faster than using babel-plugin-transform-imports + @rolldown/plugin-babel

The implementation is based on swc-project/plugins/packages/transform-imports (Apache License 2.0) and test cases are also adapted from it.

Normally, the lazy barrel feature in Rolldown (currently experimental) resolves the performance problem. But in some edge cases, this plugin can improve the performance further by ignoring minor semantics.

@sapphi-red sapphi-red force-pushed the feat/add-transform-imports-plugin branch from 9325774 to f790660 Compare April 8, 2026 08:38
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 8, 2026

Open in StackBlitz

@rolldown/plugin-babel

pnpm add https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-babel@51 -D
npm i https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-babel@51 -D
yarn add https://pkg.pr.new/rolldown/plugins/@rolldown/[email protected] -D

@rolldown/plugin-emotion

pnpm add https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-emotion@51 -D
npm i https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-emotion@51 -D
yarn add https://pkg.pr.new/rolldown/plugins/@rolldown/[email protected] -D

@rolldown/plugin-jsx-remove-attributes

pnpm add https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-jsx-remove-attributes@51 -D
npm i https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-jsx-remove-attributes@51 -D
yarn add https://pkg.pr.new/rolldown/plugins/@rolldown/[email protected] -D

oxc-unshadowed-visitor

pnpm add https://pkg.pr.new/rolldown/plugins/oxc-unshadowed-visitor@51 -D
npm i https://pkg.pr.new/rolldown/plugins/oxc-unshadowed-visitor@51 -D
yarn add https://pkg.pr.new/rolldown/plugins/[email protected] -D

@rolldown/plugin-styled-jsx

pnpm add https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-styled-jsx@51 -D
npm i https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-styled-jsx@51 -D
yarn add https://pkg.pr.new/rolldown/plugins/@rolldown/[email protected] -D

@rolldown/plugin-transform-imports

pnpm add https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-transform-imports@51 -D
npm i https://pkg.pr.new/rolldown/plugins/@rolldown/plugin-transform-imports@51 -D
yarn add https://pkg.pr.new/rolldown/plugins/@rolldown/[email protected] -D

commit: 5c945d9

@shulaoda
Copy link
Copy Markdown
Member

I prefer the following form:

transformImports({
  'mock-lib': {
    transform: 'mock-lib/{{kebabCase member}}',
  },
});

rather than:

transformImports({
  modules: {
    'mock-lib': {
      transform: 'mock-lib/{{kebabCase member}}',
    },
  },
});

First, the modules field feels redundant and unnecessary. Second, the former aligns better with the configuration style used by the corresponding plugins in Babel and SWC.

@shulaoda
Copy link
Copy Markdown
Member

I pushed a small change. If you think it’s not appropriate, we can revert it at any time.

@sapphi-red
Copy link
Copy Markdown
Member Author

It was to allow adding options in the future, but I guess it's ok to remove it.

@sapphi-red sapphi-red marked this pull request as ready for review April 20, 2026 02:28
@sapphi-red sapphi-red requested a review from shulaoda April 20, 2026 02:28
@sapphi-red sapphi-red self-assigned this Apr 20, 2026
@shulaoda
Copy link
Copy Markdown
Member

It was to allow adding options in the future, but I guess it's ok to remove it.

Yes, I had the same thought about why it’s implemented that way. But after reconsidering, I think for now we should just focus on keeping things aligned. We can revisit and enhance the functionality later when there’s an actual user need.

@sapphi-red sapphi-red merged commit 0104dfa into main Apr 20, 2026
11 checks passed
@sapphi-red sapphi-red deleted the feat/add-transform-imports-plugin branch April 20, 2026 04:53
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