From 7ee2de7ee805061410a78d2681cd340a072d0072 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 15 Jun 2021 12:41:15 +0800 Subject: [PATCH] feat(utils): `extraTransformTargets` support custom function --- packages/plugin-utils/src/createUtils.ts | 4 ++-- packages/plugin-utils/src/options.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/plugin-utils/src/createUtils.ts b/packages/plugin-utils/src/createUtils.ts index 607288ce..5b7acfe9 100644 --- a/packages/plugin-utils/src/createUtils.ts +++ b/packages/plugin-utils/src/createUtils.ts @@ -126,7 +126,7 @@ export function createUtils( } function isDetectTarget(id: string) { - if (options.scanOptions.extraTransformTargets.detect.includes(id)) + if (options.scanOptions.extraTransformTargets.detect.some(i => typeof i === 'string' ? i === id : i(id))) return true if (files.includes(id) || files.includes(id.slice(0, id.indexOf('?')))) return true @@ -141,7 +141,7 @@ export function createUtils( } function isCssTransformTarget(id: string) { - if (options.scanOptions.extraTransformTargets.css.includes(id)) + if (options.scanOptions.extraTransformTargets.css.some(i => typeof i === 'string' ? i === id : i(id))) return true if (id.match(/\.(?:postcss|scss|sass|css|stylus|less)(?:$|\?)/i) && !isExcluded(id)) return true diff --git a/packages/plugin-utils/src/options.ts b/packages/plugin-utils/src/options.ts index 9f08d9b9..63bcc5ea 100644 --- a/packages/plugin-utils/src/options.ts +++ b/packages/plugin-utils/src/options.ts @@ -262,8 +262,8 @@ export interface ResolvedOptions { transformers: TransformerFunction[] extractors: Extractor[] extraTransformTargets: { - css: string[] - detect: string[] + css: (string | ((path: string) => boolean))[] + detect: (string | ((path: string) => boolean))[] } }