Skip to content

Commit

Permalink
✨ feat: support custom exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
yunsii committed Jul 27, 2024
1 parent ceed749 commit fb4dab2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
clsTags = [],
polishTags = [] as PolishTag[],
debug = false,
exclude,
} = options || {}

if (debug) {
Expand All @@ -31,13 +32,17 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
if (IS_DEV) {
return false
}
const normalizedId = pathe.normalize(id)
if (normalizedId.includes('node_modules')) {
return false
}
if (exclude && exclude(normalizedId)) {
return false
}
const extensions = ['ts', 'tsx', 'js', 'jsx', ...moreExtensions]
return extensions.some((item) => id.endsWith(`.${item}`))
},
transform(code, id) {
if (pathe.normalize(id).includes('node_modules')) {
return
}
try {
const polishCode = transformTags(code, {
clsTags,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface Options {
*/
polishTags?: PolishTag[]
debug?: boolean
/** Custom exclude for better performance */
exclude?: (id: string) => boolean
}

export type PolishCallback = (str: string) => string | void
Expand Down

0 comments on commit fb4dab2

Please sign in to comment.