Skip to content

Commit 206d8d1

Browse files
authored
Merge pull request #15 from crashmax-dev/tampermonkey-types
feat: added Tampermonkey's type difinition
2 parents 50478f0 + 165794b commit 206d8d1

File tree

14 files changed

+873
-133
lines changed

14 files changed

+873
-133
lines changed

README.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- 🔧 Configure Tampermonkey's Userscript header.
1313
- 💨 Import all `grant` by default in development mode.
1414
- 📝 Automatically add used `grant` when building for production.
15+
- 📦 Built-in Tampermonkey's TypeScript type difinition.
1516

1617
## Install
1718

@@ -36,21 +37,23 @@ import { defineConfig } from 'vite'
3637
import Userscript from 'vite-userscript-plugin'
3738
import { name, version } from './package.json'
3839

39-
export default defineConfig({
40-
plugins: [
41-
Userscript({
42-
entry: 'src/index.ts',
43-
header: {
44-
name,
45-
version,
46-
match: [
47-
'https://example.com',
48-
'https://example.org',
49-
'https://example.edu'
50-
]
51-
}
52-
})
53-
]
40+
export default defineConfig((config) => {
41+
return {
42+
plugins: [
43+
Userscript({
44+
entry: 'src/index.ts',
45+
header: {
46+
name,
47+
version,
48+
match: [
49+
'*://example.com',
50+
'*://example.org',
51+
'*://example.edu'
52+
]
53+
}
54+
})
55+
]
56+
}
5457
})
5558
```
5659

@@ -65,6 +68,18 @@ export default defineConfig({
6568
}
6669
```
6770

71+
### `tsconfig.json`
72+
73+
```json
74+
{
75+
"compilerOptions": {
76+
"types": [
77+
"vite-userscript-plugin/tampermonkey"
78+
]
79+
}
80+
}
81+
```
82+
6883
## Plugin Configuration
6984

7085
```ts

examples/basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "vite build --watch",
7+
"dev": "vite build --watch --mode development",
88
"build": "vite build"
99
},
1010
"devDependencies": {

examples/basic/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ import './styles/style.sass'
44

55
const div = document.querySelector('div')!
66
div.appendChild(createButton())
7+
8+
GM_addStyle('')

examples/basic/src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/// <reference types="vite/client" />
2+
/// <reference types="vite-userscript-plugin/tampermonkey" />

examples/basic/tsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"extends": "@crashmax/tsconfig",
33
"compilerOptions": {
4-
"outDir": "dist",
5-
"resolveJsonModule": true
6-
}
4+
"outDir": "dist"
5+
},
6+
"include": [
7+
"src/**/*"
8+
]
79
}

examples/basic/vite.config.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@ import { defineConfig } from 'vite'
22
import Userscript from 'vite-userscript-plugin'
33
import { name, version } from './package.json'
44

5-
export default defineConfig({
6-
plugins: [
7-
Userscript({
8-
entry: 'src/index.ts',
9-
header: {
10-
name,
11-
version,
12-
match: [
13-
'*://example.com',
14-
'*://example.org',
15-
'*://example.edu'
16-
]
17-
}
18-
})
19-
]
5+
export default defineConfig((config) => {
6+
return {
7+
plugins: [
8+
Userscript({
9+
entry: 'src/index.ts',
10+
header: {
11+
name,
12+
version,
13+
match: [
14+
'*://example.com',
15+
'*://example.org',
16+
'*://example.edu'
17+
]
18+
},
19+
server: {
20+
port: 3000
21+
}
22+
})
23+
]
24+
}
2025
})

examples/jsx/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "vite build --watch",
7+
"dev": "vite build --watch --mode development",
88
"build": "vite build"
99
},
1010
"devDependencies": {
@@ -13,6 +13,6 @@
1313
"vite-userscript-plugin": "workspace:*"
1414
},
1515
"dependencies": {
16-
"redom-jsx": "^3.29.3"
16+
"redom-jsx": "^3.29.4"
1717
}
1818
}

examples/jsx/tsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"extends": "@crashmax/tsconfig",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"resolveJsonModule": true,
6-
"jsx": "preserve"
5+
"jsx": "preserve",
6+
"types": [
7+
"vite-userscript-plugin/tampermonkey"
8+
]
79
},
810
"include": [
9-
"src"
11+
"src/**/*"
1012
]
1113
}

examples/jsx/vite.config.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ import Redom from 'vite-redom-jsx'
33
import Userscript from 'vite-userscript-plugin'
44
import { name, version } from './package.json'
55

6-
export default defineConfig({
7-
plugins: [
8-
Redom(),
9-
Userscript({
10-
entry: 'src/index.tsx',
11-
header: {
12-
name,
13-
version,
14-
match: '*://example.com'
15-
}
16-
})
17-
]
6+
export default defineConfig((config) => {
7+
return {
8+
plugins: [
9+
Redom(),
10+
Userscript({
11+
entry: 'src/index.tsx',
12+
header: {
13+
name,
14+
version,
15+
match: '*://example.com'
16+
},
17+
server: {
18+
port: 4000
19+
}
20+
})
21+
]
22+
}
1823
})

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"import": "./dist/index.js"
1111
},
1212
"files": [
13-
"dist"
13+
"dist",
14+
"tampermonkey.d.ts"
1415
],
1516
"scripts": {
1617
"dev": "tsup --watch",
@@ -44,7 +45,6 @@
4445
"url": "https://github.com/crashmax-dev/vite-userscript-plugin/issues"
4546
},
4647
"dependencies": {
47-
"@types/tampermonkey": "^4.0.5",
4848
"get-port": "^6.1.2",
4949
"open": "^8.4.0",
5050
"picocolors": "^1.0.0",
@@ -60,14 +60,13 @@
6060
"@types/websocket": "^1.0.5",
6161
"@vitest/ui": "^0.23.2",
6262
"tsup": "^6.2.3",
63-
"turbo": "^1.4.6",
63+
"turbo": "^1.4.7",
6464
"typescript": "^4.8.3",
65-
"vite": "^3.1.1",
65+
"vite": "^3.1.2",
6666
"vite-plugin-dts": "^1.5.0",
6767
"vitest": "^0.23.2"
6868
},
6969
"peerDependencies": {
70-
"@types/tampermonkey": ">=4.0.0",
7170
"vite": ">=2.9.0"
7271
}
7372
}

0 commit comments

Comments
 (0)