Skip to content

feat: allow passing custom swc configuration to swcPlugin#1313

Merged
egoist merged 2 commits into
egoist:mainfrom
Romakita:feat-swc-configuration
May 16, 2025
Merged

feat: allow passing custom swc configuration to swcPlugin#1313
egoist merged 2 commits into
egoist:mainfrom
Romakita:feat-swc-configuration

Conversation

@Romakita
Copy link
Copy Markdown
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
  }
})

@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented Mar 4, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@vercel
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

Very Good!

@pkg-pr-new
Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

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

vaernion pushed a commit to Arbeidstilsynet/brevgen2 that referenced this pull request Dec 3, 2025
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [tsup](https://tsup.egoist.dev/) ([source](https://github.com/egoist/tsup)) | [`8.4.0` -> `8.5.0`](https://renovatebot.com/diffs/npm/tsup/8.4.0/8.5.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/tsup/8.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/tsup/8.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/tsup/8.4.0/8.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/tsup/8.4.0/8.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>egoist/tsup (tsup)</summary>

### [`v8.5.0`](https://github.com/egoist/tsup/releases/tag/v8.5.0)

[Compare Source](egoist/tsup@v8.4.0...v8.5.0)

#####    🚀 Features

-   Use `fix-dts-default-cjs-exports` to transform CJS types  -  by [@&#8203;userquin](https://github.com/userquin) in egoist/tsup#1310 [<samp>(c654e)</samp>](egoist/tsup@c654e5f)
-   Allow passing custom swc configuration to swcPlugin  -  by [@&#8203;Romakita](https://github.com/Romakita) in egoist/tsup#1313 [<samp>(fdfd5)</samp>](egoist/tsup@fdfd59a)

#####    🐞 Bug Fixes

-   Make `removeNodeProtocol` work with `shims`  -  by [@&#8203;aryaemami59](https://github.com/aryaemami59) [<samp>(769aa)</samp>](egoist/tsup@769aa49)
-   CopyPublicDir in watch mode  -  by [@&#8203;geeee](https://github.com/geeee) in egoist/tsup#1331 [<samp>(7c1e1)</samp>](egoist/tsup@7c1e13e)

#####     [View changes on GitHub](egoist/tsup@v8.4.0...v8.5.0)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or PR is renamed to start with "rebase!".

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Related work items: #30372
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