fix(web-extension): Fix types in vite config (#1333)

This commit is contained in:
Billy Vong
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 910fa46d78
commit 2de4c0d326
2 changed files with 19 additions and 9 deletions

View File

@@ -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.