From 5dd7e9e5c655fdd718e5c1dfd7b39f7fe91e10bc Mon Sep 17 00:00:00 2001 From: Janne Holm Date: Wed, 13 Sep 2023 12:21:39 +0300 Subject: [PATCH] Added backgroundscripts support for Firefox --- packages/vite-plugin/src/node/files.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/vite-plugin/src/node/files.ts b/packages/vite-plugin/src/node/files.ts index 2058b1624..c9962d9af 100644 --- a/packages/vite-plugin/src/node/files.ts +++ b/packages/vite-plugin/src/node/files.ts @@ -1,7 +1,7 @@ import fg from 'fast-glob' -import { isString } from './helpers' -import { ChromeManifestBackground, ManifestV3 } from './manifest' +import { ManifestV3 } from './manifest' import { ManifestFiles } from './types' +import { isString } from './helpers' export async function manifestFiles( manifest: ManifestV3, @@ -19,10 +19,12 @@ export async function manifestFiles( const contentScripts = manifest.content_scripts?.flatMap(({ js }) => js) ?? [] const contentStyles = manifest.content_scripts?.flatMap(({ css }) => css) + + const serviceWorker = manifest.background && "service_worker" in manifest.background ? manifest.background.service_worker : undefined; + const backgroundScripts = manifest.background && "scripts" in manifest.background ? manifest.background.scripts : undefined; + const background = serviceWorker ? [serviceWorker].filter(isString) : backgroundScripts ? backgroundScripts.filter(isString) : []; + const htmlPages = htmlFiles(manifest) - const serviceWorker = ( - manifest.background as ChromeManifestBackground | undefined - )?.service_worker const icons = [ Object.values( @@ -57,7 +59,7 @@ export async function manifestFiles( icons: [...new Set(icons)].filter(isString), locales: [...new Set(locales)].filter(isString), rulesets: [...new Set(rulesets)].filter(isString), - background: [serviceWorker].filter(isString), + background: background, webAccessibleResources, } }