Skip to content

Commit

Permalink
Allow reloading for content_scripts indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Dec 27, 2024
1 parent 4871e26 commit 4a43088
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export class EmitManifest {
}

apply(compiler: Compiler): void {
compiler.hooks.compilation.tap(
compiler.hooks.thisCompilation.tap(
'manifest:emit-manifest',
(compilation: Compilation) => {
compilation.hooks.processAssets.tap(
{
name: 'manifest:emit-manifest',
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
},
() => {
const manifestPath = this.manifestPath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'
import type webpack from 'webpack'
import WebExtension from 'webpack-target-webextension'
import WebExtension from './webpack-target-webextension'
import {type PluginInterface} from '../../../reload-types'
import {type Manifest} from '../../../../webpack-types'
import {type DevOptions} from '../../../../../commands/commands-lib/config-types'
Expand Down Expand Up @@ -134,9 +134,34 @@ export class TargetWebExtensionPlugin {

this.handleBackground(compiler, this.browser, patchedManifest)

// Generate experimental_output for all content_scripts
const experimentalOutput: Record<
string,
(manifest: Manifest, list: string[]) => void
> = {}

if (Array.isArray(patchedManifest.content_scripts)) {
const contentScripts: Manifest['content_scripts'] =
patchedManifest.content_scripts
contentScripts?.forEach((script, index) => {
const key = `content_scripts/content-${index}`
experimentalOutput[key] = (manifest, list) => {
if (manifest.content_scripts && manifest.content_scripts[index]) {
console.log({
key,
manifest,
list
})
manifest.content_scripts[index].js = list
}
}
})
}

new WebExtension({
background: this.getEntryName(patchedManifest),
weakRuntimeCheck: true
weakRuntimeCheck: true,
experimental_output: experimentalOutput
}).apply(compiler)
}
}

0 comments on commit 4a43088

Please sign in to comment.