Install:
pnpm add @dktpham/rsbuild-user-script-plugin -D
yarn add @dktpham/rsbuild-user-script-plugin -D
Add the plugin to your rsbuild.config.ts
and configure accordingly:
// rsbuild.config.ts
import { pluginUserScript } from "@dktpham/rsbuild-user-script-plugin";
export default defineConfig({
plugins: [
pluginUserScript({
entry: "./src/index.js",
name: "My User Script",
author: "Me",
version: "0.0.1",
headerEntries: [
// configure any headers you need
"// @match https://*/*",
],
description: "does something",
}),
],
output: {
minify: false,
}
})
The plugin also hooks into the rsbuild
development server to allow for hot reloading of a dev build
or installing a build into your browser.
You need the following scripts that should come by default anyway:
{
"scripts": {
"dev": "rsbuild dev",
"preview": "rsbuild preview",
"build": "rsbuild build"
}
}
You also need to configure Tampermonkey to always update externals. The hot reloading solution was taken from https://github.com/momocow/webpack-userscript. Please take look there to setup Tampermonkey otherwise you'd have to manually update the script every time.
Options for configuring pluginUserScript
.
-
entry (required)
- Type:
string
- Description: The entry file for the user script.
- Type:
-
name (required)
- Type:
string
- Description: The name of the user script.
- Type:
-
author (required)
- Type:
string
- Description: The author of the user script.
- Type:
-
version (required)
- Type:
string
- Description: The version of the user script.
- Type:
-
description (required)
- Type:
string
- Description: The description of the user script.
- Type:
-
headerEntries (optional)
- Type:
string[]
- Default:
[]
- Description: Additional header entries for the user script.
- Type:
-
createHeader (optional)
- Type:
(other: string[]) => string
- Default: see ./src/index.ts
- Description: A function to create the header for the user script.
- Type:
-
createProxyHeader (optional)
- Type:
(serverPort: number, filename: string, other: string[]) => string
- Default: see ./src/index.ts
- Description: A function to create the proxy header for the user script.
- Type:
MIT.