vite-userscript-plugin 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # vite-userscript-plugin
2
+
3
+ ![ci](https://img.shields.io/github/workflow/status/crashmax-dev/vite-userscript-plugin/npm-publish)
4
+ ![npm](https://img.shields.io/npm/v/vite-userscript-plugin)
5
+ ![license](https://img.shields.io/github/license/crashmax-dev/vite-userscript-plugin)
6
+
7
+ > Tampermonkey userscript developing and build plugin based on [Vite](https://vitejs.dev).
8
+
9
+ ## Features
10
+
11
+ - 🔥 Hot reloading after changing any files.
12
+ - 🔧 Configure Tampermonkey's Userscript header.
13
+ - 💨 Import all `grant` by default in development mode.
14
+ - 📝 Automatically add used `grant` when building for production.
15
+
16
+ ## Install
17
+
18
+ ```
19
+ npm install vite-userscript-plugin -D
20
+ ```
21
+
22
+ ```
23
+ yarn add vite-userscript-plugin -D
24
+ ```
25
+
26
+ ```
27
+ pnpm add vite-userscript-plugin -D
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### `vite.config.ts`
33
+
34
+ ```js
35
+ import { resolve } from 'path'
36
+ import { defineConfig } from 'vite'
37
+ import { UserscriptPlugin } from 'vite-userscript-plugin'
38
+ import { name, version } from './package.json'
39
+
40
+ export default defineConfig({
41
+ plugins: [
42
+ UserscriptPlugin({
43
+ entry: resolve(__dirname, 'src/index.ts'),
44
+ metadata: {
45
+ name,
46
+ version,
47
+ match: [
48
+ 'https://example.com',
49
+ 'https://example.org',
50
+ 'https://example.edu'
51
+ ]
52
+ }
53
+ })
54
+ ]
55
+ })
56
+ ```
57
+
58
+ ### `package.json`
59
+
60
+ ```json
61
+ {
62
+ "scripts": {
63
+ "dev": "vite build --watch",
64
+ "build": "vite build"
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## Plugin Configuration
70
+
71
+ ```ts
72
+ export interface UserscriptPluginConfig {
73
+ /**
74
+ * Path of userscript entry.
75
+ */
76
+ entry: string
77
+
78
+ /**
79
+ * Userscript header config.
80
+ */
81
+ metadata: MetadataConfig
82
+
83
+ /**
84
+ * Import all `@grant` in development mode.
85
+ * @default true
86
+ */
87
+ autoGrants?: boolean
88
+
89
+ /**
90
+ * Server config (used in development mode for hot reloading).
91
+ */
92
+ server?: ServerConfig
93
+ }
94
+ ```
95
+
96
+ ## Example
97
+
98
+ See the [example](https://github.com/crashmax-dev/vite-userscript-plugin/tree/master/packages/demo) folder.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PluginOption } from 'vite';
2
- import type { PluginConfig } from './types.js';
3
- declare function UserscriptPlugin(config: PluginConfig): PluginOption;
2
+ import type { UserscriptPluginConfig } from './types.js';
3
+ declare function UserscriptPlugin(config: UserscriptPluginConfig): PluginOption;
4
4
  export { UserscriptPlugin };
5
5
  export default UserscriptPlugin;
6
- export type { PluginConfig };
6
+ export type { UserscriptPluginConfig };
package/dist/index.js CHANGED
@@ -82,7 +82,7 @@ function UserscriptPlugin(config) {
82
82
  // prettier-ignore
83
83
  config.metadata.grant = removeDuplicates(isBuildWatch
84
84
  ? grants
85
- : config.autoGrants
85
+ : config.autoGrants ?? true
86
86
  ? defineGrants(file)
87
87
  : [...(config.metadata.grant ?? []), 'GM_addStyle', 'GM_info']);
88
88
  // prettier-ignore-end
package/dist/types.d.ts CHANGED
@@ -191,22 +191,27 @@ export declare type MetadataConfig = {
191
191
  };
192
192
  export interface ServerConfig {
193
193
  /**
194
+ * Server port.
194
195
  * @default 8000
195
196
  */
196
197
  port?: number;
197
198
  }
198
- export interface PluginConfig {
199
+ export interface UserscriptPluginConfig {
199
200
  /**
200
201
  * Path of userscript entry.
201
202
  */
202
203
  entry: string;
203
204
  /**
204
- * @default false
205
+ * Userscript header config.
206
+ */
207
+ metadata: MetadataConfig;
208
+ /**
209
+ * Import all `@grant` in development mode.
210
+ * @default true
205
211
  */
206
212
  autoGrants?: boolean;
207
- server?: ServerConfig;
208
213
  /**
209
- * Userscript Metadata config.
214
+ * Server config (used in development mode for hot reloading).
210
215
  */
211
- metadata: MetadataConfig;
216
+ server?: ServerConfig;
212
217
  }
package/package.json CHANGED
@@ -1,12 +1,31 @@
1
1
  {
2
2
  "name": "vite-userscript-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/crashmax-dev/vite-userscript-plugin.git"
13
+ },
14
+ "keywords": [
15
+ "vite",
16
+ "vite-plugin",
17
+ "userscript",
18
+ "tampermonkey"
19
+ ],
20
+ "author": {
21
+ "name": "Vitalij Ryndin",
22
+ "email": "sys@crashmax.ru",
23
+ "url": "https://crashmax.ru"
24
+ },
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/crashmax-dev/vite-userscript-plugin/issues"
28
+ },
10
29
  "dependencies": {
11
30
  "websocket": "^1.0.34"
12
31
  },