1.11.0 • Published 8 months ago
vite-userscript-plugin v1.11.0
vite-userscript-plugin
⚡️ 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
1.11.0
8 months ago
1.9.1
2 years ago
1.9.0
2 years ago
1.9.2
2 years ago
1.10.0
2 years ago
1.8.1
2 years ago
1.7.2
2 years ago
1.8.0
2 years ago
1.7.1
2 years ago
1.7.0
2 years ago
1.6.7
2 years ago
1.6.4
2 years ago
1.6.3
2 years ago
1.6.2
2 years ago
1.6.6
2 years ago
1.6.5
2 years ago
1.2.0
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.0
3 years ago
1.6.1
3 years ago
1.6.0
3 years ago
1.5.0
3 years ago
1.4.0
3 years ago
1.2.2
3 years ago
1.3.0
3 years ago
1.2.1
3 years ago
1.1.2
3 years ago
0.9.0
3 years ago
0.9.2
3 years ago
0.9.1
3 years ago
0.8.3
3 years ago
0.8.2
3 years ago
0.8.1
3 years ago
0.8.0
3 years ago
0.7.0
3 years ago
0.6.1
3 years ago
0.5.0
3 years ago
0.4.0
3 years ago
0.3.0
3 years ago
0.2.0
3 years ago
0.1.0
3 years ago
0.0.0
3 years ago