vite-userscript-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.11.0 • Public • Published

vite-userscript-plugin

npm license template

⚡️ A plugin for developing and building a Tampermonkey userscript based on Vite.

Table of contents

Features

  • 🔥 Reloading page after changing any files.
  • 🔧 Configure Tampermonkey's Userscript header.
  • 💨 Import all grant's to the header by default in development mode.
  • 📝 Automatic addition of used grant's in the code when building for production.
  • 📦 Built-in Tampermonkey's TypeScript type definition.

Install

npm install vite-userscript-plugin -D
yarn add vite-userscript-plugin -D
pnpm add vite-userscript-plugin -D

Setup config

import { defineConfig } from 'vite'
import Userscript from 'vite-userscript-plugin'
import { name, version } from './package.json'

export default defineConfig((config) => {
  return {
    plugins: [
      Userscript({
        entry: 'src/index.ts',
        header: {
          name,
          version,
          match: [
            'https://example.com/',
            'https://example.org/',
            'https://example.edu/'
          ]
        },
        server: {
          port: 3000
        }
      })
    ]
  }
})

Setup NPM scripts

// package.json
{
  "scripts": {
    "dev": "vite build --watch --mode development",
    "build": "vite build"
  }
}

Setup TypeScript types

// tsconfig.json
{
  "compilerOptions": {
    "types": [
      "vite-userscript-plugin/types/tampermonkey"
    ]
  }
}

Using style modules

import style from './style.css?raw'

// inject style element
const styleElement = GM_addStyle(style)

// remove style element
styleElement.remove()

Plugin configuration

interface ServerConfig {
  /**
   * {@link https://github.com/sindresorhus/get-port}
   */
  port?: number;

  /**
   * @default false
   */
  open?: boolean;
}

interface UserscriptPluginConfig {
  /**
   * Path of userscript entry.
   */
  entry: string;

  /**
   * Userscript header config.
   *
   * @see https://www.tampermonkey.net/documentation.php
   */
  header: HeaderConfig;

  /**
   * Server config.
   */
  server?: ServerConfig;
}

Examples

See the examples folder.

License

MIT © crashmax

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.11.016latest

Version History

VersionDownloads (Last 7 Days)Published
1.11.016
1.10.05
1.9.20
1.9.10
1.9.00
1.8.11
1.8.00
1.7.20
1.7.10
1.7.00
1.6.72
1.6.60
1.6.50
1.6.40
1.6.30
1.6.20
1.6.10
1.6.00
1.5.00
1.4.00
1.3.00
1.2.20
1.2.10
1.2.00
1.1.20
1.1.10
1.1.00
1.0.00
0.9.20
0.9.10
0.9.00
0.8.30
0.8.20
0.8.10
0.8.00
0.7.00
0.6.10
0.5.00
0.4.00
0.3.00
0.2.00
0.1.00
0.0.00

Package Sidebar

Install

npm i vite-userscript-plugin

Weekly Downloads

24

Version

1.11.0

License

MIT

Unpacked Size

93.1 kB

Total Files

10

Last publish

Collaborators

  • crashmax