Skip to content

Commit

Permalink
fix: background scripts for firefox build (#790)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Steam <jacksteamdev@gmail.com>
  • Loading branch information
VadimSaveljev and jacksteamdev committed Oct 16, 2023
1 parent 54002ea commit f5c4bd7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-geckos-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@crxjs/vite-plugin": patch
---

fix: background scripts for firefox build
1 change: 1 addition & 0 deletions packages/vite-plugin/src/node/plugin-background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const pluginBackground: CrxPluginFn = () => {
} else {
manifest.background = {
scripts: [this.getFileName(refId)],
type: 'module',
}
}

Expand Down
17 changes: 17 additions & 0 deletions packages/vite-plugin/src/node/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ export const pluginManifest: CrxPluginFn = () => {
manifest.background.service_worker = refId
}

if (manifest.background && 'scripts' in manifest.background) {
const file = manifest.background.scripts[0]
const id = join(config.root, file)
const refId = this.emitFile({
type: 'chunk',
id,
name: basename(file),
})
manifest.background.scripts = [refId]
}

for (const file of htmlFiles(manifest)) {
const id = join(config.root, file)
this.emitFile({
Expand Down Expand Up @@ -278,6 +289,12 @@ export const pluginManifest: CrxPluginFn = () => {
manifest.background.service_worker = name
}

if (manifest.background && 'scripts' in manifest.background) {
const ref = manifest.background.scripts[0]
const name = this.getFileName(ref)
manifest.background.scripts = [name]
}

// update content script file names from refs
// TODO: emit and parse css
manifest.content_scripts = manifest.content_scripts?.map(
Expand Down

0 comments on commit f5c4bd7

Please sign in to comment.