Skip to content

Commit

Permalink
docs(README): add comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Apr 16, 2022
1 parent e8c4d79 commit 29c7dfa
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@

[SWC](https://swc.rs/) is an extensible Rust-based platform for the next generation of fast developer tools. This plugin is designed to replace `rollup-plugin-typescript2`, `@rollup/plugin-typescript`, `@rollup/plugin-babel` and `rollup-plugin-terser` for you.

## Comparison

| | [sukkaw/rollup-plugin-swc](https://github.com/SukkaW/rollup-plugin-swc) | [mentaljam/rollup-plugin-swc](https://github.com/mentaljam/rollup-plugin-swc) | [nicholasxjy/rollup-plugin-swc2](https://github.com/nicholasxjy/rollup-plugin-swc2)
| --- | --- | --- | --- |
| `minify` your bundle in one pass[^1] | Yes | No | No |
| Standalone `swcMinify` plugin | Yes | No | No |
| Config Intellisense[^2] | Yes | No | No |
| Reads your `tsconfig.json` and `jsconfig.json` | Yes[^3] | No | No |
| ESM export | Full | Partial[^4] | No |
| TypeScrit declarations | Yes | Yes | Yes |
| Has testing | Yes | No | No |

[^1]: If minify is called in Rollup's `transform` phase, every individual module processed will result in a minify call. However, if minify is called in Rollup's `renderChunk` phase, the minify will only be called once in one whole pass before Rollup generates bundle, results in a faster build.
[^2]: Autocompletion and type checking in your IDE
[^3]: `extends` is not supported.
[^4]: `mentaljam/rollup-plugin-swc` has both `main` and `module` fields in `package.json`, but has no `exports` field.

## Install

```bash
Expand Down Expand Up @@ -53,6 +70,10 @@ export default {
})),
];
}

// or
/** @type {imoprt('rollup-plugin-swc3').PluginOptions} */
const swcPluginConfig = {}
```

- `include` and `exclude` can be `String | RegExp | Array<String | RegExp>`, when supplied it will override default values.
Expand All @@ -61,7 +82,7 @@ export default {
- `jsconfig.json` will be ignored if `tsconfig.json` and `jsconfig.json` both exist.
- `baseUrl` and `paths` will be passed to swc directly. They won't affect how rollup resolve your imports. Please use other plugins to resolve your imports' aliases (e.g., add [rollup-plugin-typescript-paths](https://www.npmjs.com/package/rollup-plugin-typescript-paths) or [rollup-plugin-tsconfig-paths](https://www.npmjs.com/package/rollup-plugin-tsconfig-paths) before `@rollup/plugin-node-resolve`).

## Standalone Minify Plugin
### Standalone Minify Plugin

If you only want to use `swc` to minify your bundle:

Expand Down Expand Up @@ -89,16 +110,28 @@ export default {
// compress: {}
}))],
}

// or
/** @type {import('@swc/core').JsMinifyOptions} */
const swcMinifyConfig = {}
```

### Write your Rollup config in TypeScript

You can write your Rollup config file in `rollup.config.ts`, and use the following command:

```sh
rollup --config rollup.config.ts --configPlugin swc3
```

## Declaration File
### TypeScript Declaration File

There are serveral ways to generate declaration file:

- Use `tsc` with `emitDeclarationOnly`, the slowest way but you get type checking, it doesn't bundle the `.d.ts` files.
- Use `rollup-plugin-dts` which generates and bundle `.d.ts`, also does type checking. It is used by this plugin as well.

## Use with Non-react JSX
### Use with Non-react JSX

You can either configure it in your `tsconfig.json` or in your `rollup.config.js`.

Expand Down

0 comments on commit 29c7dfa

Please sign in to comment.