A Webpack 5 plugin (also works with Rspack) that provides presets and fixes for building Web Extensions (Chrome, Firefox). It enables code splitting via dynamic import() and classic loaders, Hot Module Reload, and correct public path handling. Current stable version is 2.1.3, released under the MIT license. Key differentiators: supports Manifest V2 and V3, works with both webpack and rspack, and includes built-in chunk loaders for content scripts and background scripts. Note: webpack 4 users must use version 0.2.1.
npm install webpack-target-webextensionVerified import paths — ran on the pinned version, not inferred.
Minimal webpack config for a Web Extension using the plugin. Sets up entries for background, content script, and options page, with HTML generation and manifest copy.
Add '/*.js' to web_accessible_resources in manifest.json with appropriate matches.
Include 'scripting' in permissions and set background: { pageEntry: 'background' } with no classicLoader: false.Use 'npm install webpack-target-webextension@0.2.1' for webpack 4.
Add '"resources": ["/hot/*.js", "/hot/*.json"], "matches": ["<all_urls>"]' to web_accessible_resources.
For older browsers, set output.environment.dynamicImport to false to use alternative methods, or use the classic loader.
Add '"resources": ["/*.js"], "matches": ["<all_urls>"]' to your manifest.json's web_accessible_resources.
Configure the WebExtension plugin with background: { pageEntry: 'background' } in webpack config, and ensure the background entry exists.Downgrade to version 0.2.1: 'npm install webpack-target-webextension@0.2.1'.
Run 'npm install webpack-target-webextension --save-dev'.