vite-userscript-plugin
v1.11.0
Published
[](https://npmjs.com/vite-userscript-plugin) [](./LICENCE) [ => {
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.
