From 03e8fba64c58d6a2c1bb3e906835ea9eecd4f825 Mon Sep 17 00:00:00 2001 From: Daniel Heath Date: Wed, 5 Oct 2022 14:20:42 +1100 Subject: [PATCH] Add onFileCompiled callback --- packages/esbuild-plugin/src/index.ts | 3 +++ packages/integration/src/processVanillaFile.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/esbuild-plugin/src/index.ts b/packages/esbuild-plugin/src/index.ts index c86aa777b..80f85fa20 100644 --- a/packages/esbuild-plugin/src/index.ts +++ b/packages/esbuild-plugin/src/index.ts @@ -22,11 +22,13 @@ interface VanillaExtractPluginOptions { externals?: Array; runtime?: boolean; processCss?: (css: string) => Promise; + onFileCompiled?: (path: string, identifiers: Record) => void; identifiers?: IdentifierOption; esbuildOptions?: CompileOptions['esbuildOptions']; } export function vanillaExtractPlugin({ outputCss, + onFileCompiled, externals = [], runtime = false, processCss, @@ -93,6 +95,7 @@ export function vanillaExtractPlugin({ const contents = await processVanillaFile({ source, + onFileCompiled, filePath: path, outputCss, identOption, diff --git a/packages/integration/src/processVanillaFile.ts b/packages/integration/src/processVanillaFile.ts index 3090710de..118ecb76d 100644 --- a/packages/integration/src/processVanillaFile.ts +++ b/packages/integration/src/processVanillaFile.ts @@ -38,11 +38,13 @@ interface ProcessVanillaFileOptions { fileScope: FileScope; source: string; }) => string | Promise; + onFileCompiled?: (path: string, identifiers: Record) => void; } export async function processVanillaFile({ source, filePath, outputCss = true, + onFileCompiled, identOption = process.env.NODE_ENV === 'production' ? 'short' : 'debug', serializeVirtualCssPath, }: ProcessVanillaFileOptions) { @@ -96,6 +98,7 @@ export async function processVanillaFile({ { console, process, __adapter__: cssAdapter }, true, ); + onFileCompiled?.(filePath, evalResult) process.env.NODE_ENV = currentNodeEnv;