Skip to content

Commit

Permalink
Added backgroundscripts support for Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
Janne Holm authored and winstxnhdw committed Sep 13, 2023
1 parent 2f4f2dd commit 5dd7e9e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/vite-plugin/src/node/files.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 5dd7e9e

Please sign in to comment.