Registry / devops / webpack-userscript

webpack-userscript

JSON →
library3.2.3jsnpmunverified

A webpack plugin for building userscript projects targeting Tampermonkey, Greasemonkey, Violentmonkey, and similar userscript engines. Current stable version is 3.2.3 (Dec 2024), with active maintenance on GitHub. The plugin automatically generates userscript headers from metadata, produces .meta.js files for update checks, and creates proxy scripts to avoid caching during development. Key differentiators: full TypeScript support since v3, multi-entry support, header interpolation, and integrated hot-reload workflow with webpack-dev-server. Requires webpack 5 as a peer dependency.

devops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

v3 renamed the plugin from WebpackUserscript to UserscriptPlugin. Old name no longer works.

const { UserscriptPlugin } = require('webpack-userscript');

ESM named export is supported since v3 (TypeScript rewrite). Default export does not exist.

import { UserscriptPlugin } from 'webpack-userscript';

UserscriptOptions is a type export. Use `import type` in TypeScript to avoid runtime overhead.

import type { UserscriptOptions } from 'webpack-userscript';

Configures webpack-userscript with headers, metadata generation, and proxy script for hot development with webpack-dev-server.

const path = require('path'); const { UserscriptPlugin } = require('webpack-userscript'); module.exports = { entry: './src/index.user.js', output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js', }, plugins: [ new UserscriptPlugin({ headers: { name: 'My Userscript', namespace: 'https://example.com', version: '1.0.0', description: 'A sample userscript built with webpack', author: 'You', match: 'https://example.com/*', grant: 'none', }, metajs: true, proxyScript: { baseURL: 'http://localhost:8080', }, }), ], mode: 'development', };
Debug
Known footguns
breakingIn v3.0.0, the plugin constructor was renamed from `WebpackUserscript` to `UserscriptPlugin`. Old code using `new WebpackUserscript()` will throw a ReferenceError.
breakingIn v3.0.0, the plugin was rewritten in TypeScript. CommonJS require of the default export no longer works; use named export `UserscriptPlugin`.
deprecatedThe `headers.proxyScript` option was deprecated in v3.2.0; use `proxyScript` directly in the plugin options instead.
gotchaWhen using `metajs: true`, the generated .meta.js file does not include the script body. Tampermonkey may fail update checks if the script is not hosted at the expected URL.
gotchaIf the entry file does not end with `.user.js`, the plugin will not prepend headers. Headers are only added to entry points whose names match `*.user.js`.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources