Skip to content

Commit

Permalink
feat: add include, exclude options
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Nov 12, 2021
1 parent 36e3e5b commit 095aa90
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ This plugin accepts all `@swc/core` options, except for `jsc` which should be co

Disable the use of tsconfig file or specify a custom one.

### `options.include`

- Type: `RegExp`
- Default: `/\.[jt]sx?$/`

Files to include in the transpilation process.

### `options.exclude`

- Type: `RegExp`
- Default: `/node_modules/`

Files to exclude in the transpilation process.

## Sponsors

[![sponsors](https://sponsors-images.egoist.sh/sponsors.svg)](https://github.com/sponsors/egoist)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"@egoist/prettier-config": "0.1.0",
"@rollup/pluginutils": "^4.1.1",
"@swc/core": "^1.2.108",
"esbuild": "^0.13.13",
"esbuild-register": "^3.1.2",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import { createUnplugin } from 'unplugin'
import { createFilter, FilterPattern } from '@rollup/pluginutils'

import { transform, JscConfig, Options as SwcOptions } from '@swc/core'
import { resolveId } from './resolve'
import { getCompilerOptions } from './tsconfig'

export type Options = SwcOptions & { tsconfigFile?: string | boolean }
export type Options = SwcOptions & {
include?: FilterPattern
exclude?: FilterPattern
tsconfigFile?: string | boolean
}

export default createUnplugin(
({ tsconfigFile, minify, ...options }: Options = {}) => {
({ tsconfigFile, minify, include, exclude, ...options }: Options = {}) => {
const filter = createFilter(
include || /\.[jt]sx?$/,
exclude || /node_modules/,
)

return {
name: 'swc',

resolveId,

async transform(code, id) {
if (!filter(id)) return null

const compilerOptions =
tsconfigFile === false
? {}
Expand Down

0 comments on commit 095aa90

Please sign in to comment.