diff --git a/.changeset/mighty-bulldogs-begin.md b/.changeset/mighty-bulldogs-begin.md new file mode 100644 index 0000000000..b2623ab7c8 --- /dev/null +++ b/.changeset/mighty-bulldogs-begin.md @@ -0,0 +1,5 @@ +--- +'@rrweb/web-extension': patch +--- + +Update `vite.config.ts` to account for all potential entry types. diff --git a/packages/web-extension/vite.config.ts b/packages/web-extension/vite.config.ts index 95809cb727..76d2c631a3 100644 --- a/packages/web-extension/vite.config.ts +++ b/packages/web-extension/vite.config.ts @@ -1,9 +1,4 @@ -import { - defineConfig, - LibraryFormats, - LibraryOptions, - PluginOption, -} from 'vite'; +import { defineConfig, LibraryFormats, PluginOption } from 'vite'; import webExtension, { readJsonFile } from 'vite-plugin-web-extension'; import zip from 'vite-plugin-zip-pack'; import * as path from 'path'; @@ -17,9 +12,19 @@ function useSpecialFormat( return { name: 'use-special-format', config(config) { - const shouldUse = entriesToUse.includes( - (config.build?.lib as LibraryOptions)?.entry, - ); + // entry can be string | string[] | {[entryAlias: string]: string} + const entry = config.build?.lib && config.build.lib.entry; + let shouldUse = false; + + if (typeof entry === 'string') { + shouldUse = entriesToUse.includes(entry); + } else if (Array.isArray(entry)) { + shouldUse = entriesToUse.some((e) => entry.includes(e)); + } else if (entry && typeof entry === 'object') { + const entryKeys = Object.keys(entry); + shouldUse = entriesToUse.some((e) => entryKeys.includes(e)); + } + if (shouldUse) { config.build = config.build ?? {}; // @ts-expect-error: lib needs to be an object, forcing it.