diff --git a/src/index.ts b/src/index.ts index 7b12059..967a59e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ export const unpluginFactory: UnpluginFactory = ( clsTags = [], polishTags = [] as PolishTag[], debug = false, + exclude, } = options || {} if (debug) { @@ -31,13 +32,17 @@ export const unpluginFactory: UnpluginFactory = ( 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, diff --git a/src/types.ts b/src/types.ts index d7ffacb..706e146 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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