Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/core/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { generateBiomeLintConfigs } from './biomelintrc'
import { generateESLintConfigs } from './eslintrc'
import { resolversAddon } from './resolvers'

export const INCLUDE_RE_LIST = [/\.[jt]sx?$/, /\.astro$/, /\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/, /\.svelte$/]
export const EXCLUDE_RE_LIST = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/]

export function createContext(options: Options = {}, root = process.cwd()) {
root = slash(root)

Expand Down Expand Up @@ -101,8 +104,8 @@ ${dts}`.trim()}\n`
})

const filter = createFilter(
options.include || [/\.[jt]sx?$/, /\.astro$/, /\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/, /\.svelte$/],
options.exclude || [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/],
options.include || INCLUDE_RE_LIST,
options.exclude || EXCLUDE_RE_LIST,
)
const dts = preferDTS === false
? false
Expand Down
16 changes: 12 additions & 4 deletions src/core/unplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path from 'node:path'
import { slash } from '@antfu/utils'
import { isPackageExists } from 'local-pkg'
import pm from 'picomatch'
import { createUnplugin } from 'unplugin'
import { createContext } from './ctx'
import { createUnplugin, type FilterPattern } from 'unplugin'
import { createContext, EXCLUDE_RE_LIST, INCLUDE_RE_LIST } from './ctx'

export default createUnplugin<Options>((options) => {
let ctx = createContext(options)
Expand All @@ -14,8 +14,16 @@ export default createUnplugin<Options>((options) => {
transformInclude(id) {
return ctx.filter(id)
},
async transform(code, id) {
return ctx.transform(code, id)
transform: {
filter: {
id: {
include: options.include as FilterPattern || INCLUDE_RE_LIST,
exclude: options.exclude as FilterPattern || EXCLUDE_RE_LIST,
},
},
async handler(code, id) {
return ctx.transform(code, id)
},
},
async buildStart() {
await ctx.scanDirs()
Expand Down