这是indexloc提供的服务,不要输入任何密码
Skip to content

feat: allow passing custom swc configuration to swcPlugin #1313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2025

Conversation

Romakita
Copy link
Contributor

@Romakita Romakita commented Mar 4, 2025

Information

This PR allow passing custom swc configuration to swcPlugin to solves the following issues: #1291 #1104 #1311

I know this feature isn't aligned with the tsup philosophy to minimize the configuration, but there are some needs that legitimate to introduce swc option.

Maybe a better solution can be found based on this PR ;)

Usage

When you use legacy TypeScript decorator by enabling emitDecoratorMetadata in your tsconfig, tsup will automatically use SWC to transpile
decorators. In this case, you can give extra swc configuration in the tsup.config.ts file.

For example, if you have to define useDefineForClassFields, you can do that as follows:

import { defineConfig } from 'tsup'

export default defineConfig({
  entry: ['src/index.ts'],
  splitting: false,
  sourcemap: true,
  clean: true,
  swc: {
    jsc: {
      transform: {
        useDefineForClassFields: true
      }
    }
  }
})

Note: some SWC options cannot be configured:

{
  "parser": {
    "syntax": "typescript",
    "decorators": true
  },
  "transform": {
    "legacyDecorator": true,
    "decoratorMetadata": true
  },
  "keepClassNames": true,
  "target": "es2022"
}

You can also define a custom .swcrc configuration file. Just set swcrc to true
in tsup.config.ts to allow SWC plugin to discover automatically your custom swc config file.

import { defineConfig } from 'tsup'

export default defineConfig({
  entry: ['src/index.ts'],
  splitting: false,
  sourcemap: true,
  clean: true,
  swc: {
    swcrc: true
  }
})

Copy link

codesandbox bot commented Mar 4, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Mar 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tsup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2025 5:48am

@Romakita
Copy link
Contributor Author

Hi @egoist

can you please, review this PR and tell me if it’s ok for you ;)
I’ll be happy to made any changes on this PR if it’s necessary to resolve all issue related swc configuration.

thank you!

@sonofmagic
Copy link

Very Good!

Copy link

pkg-pr-new bot commented May 16, 2025

Open in StackBlitz

npm i https://pkg.pr.new/egoist/tsup@1313

commit: cb1bfed

@egoist egoist merged commit fdfd59a into egoist:main May 16, 2025
12 checks passed
@Romakita
Copy link
Contributor Author

Thanks a lot @egoist! keep going your amazing work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants