wext-manifest-webpack-plugin
raw JSON →Webpack plugin that solves the problem of generating JS files for manifest.json entries in web extensions (Chrome, Firefox, Edge, Opera). It automatically finds JS files referenced in the manifest entry, copies the manifest to the output, and removes the generated JS file from the compilation to avoid duplicate or extraneous output. Version 1.4.1 supports both webpack 4 and 5. It is commonly used with wext-manifest-loader and the web-extension-starter project. The plugin is maintained by a single developer with updates focused on compatibility and stability. It fills a niche gap not addressed by other webpack extension plugins like @pmmmwh/react-refresh-webpack-plugin or webpack-ext-reloader by providing a minimal, focused solution for manifest handling.
Common errors
error TypeError: WextManifestWebpackPlugin is not a constructor ↓
error Module not found: Error: Can't resolve 'wext-manifest-loader' ↓
error Unexpected token 'export' in manifest.json ↓
Warnings
gotcha Plugin requires wext-manifest-loader for JSON handling; omission causes manifest not to be copied. ↓
gotcha Plugin does not accept any constructor options; passing options may lead to silent failures. ↓
gotcha The plugin is CJS-only; using ES module import will fail. ↓
deprecated Webpack 4 support is considered deprecated; upgrade to webpack 5 for best compatibility. ↓
Install
npm install wext-manifest-webpack-plugin yarn add wext-manifest-webpack-plugin pnpm add wext-manifest-webpack-plugin Imports
- WextManifestWebpackPlugin wrong
import WextManifestWebpackPlugin from 'wext-manifest-webpack-plugin';correctconst WextManifestWebpackPlugin = require('wext-manifest-webpack-plugin'); - WextManifestWebpackPlugin wrong
import WextManifestWebpackPlugin from 'wext-manifest-webpack-plugin';correctimport WextManifestWebpackPlugin = require('wext-manifest-webpack-plugin'); - Plugin wrong
new WextManifestWebpackPlugin({ ... options })correctnew WextManifestWebpackPlugin()
Quickstart
const path = require('path');
const WextManifestWebpackPlugin = require('wext-manifest-webpack-plugin');
const destPath = path.resolve(__dirname, 'dist');
const targetBrowser = 'chrome';
module.exports = {
entry: {
manifest: './source/manifest.json',
},
output: {
path: path.join(destPath, targetBrowser),
filename: 'js/[name].js',
},
module: {
rules: [
{
type: 'javascript/auto',
test: /\.json$/,
use: 'wext-manifest-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new WextManifestWebpackPlugin(),
],
};