Skip to content

Commit 7090e1d

Browse files
authored
Merge pull request #28 from greasify/feat/remove-css-inject
feat: remove css injecting, update apis
2 parents 2b526bd + dd95a55 commit 7090e1d

34 files changed

+4210
-2643
lines changed

.github/workflows/npm-publish.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ jobs:
1111

1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- name: Install Node.js
17-
uses: actions/setup-node@v3
17+
uses: actions/setup-node@v4
1818
with:
19-
node-version: 18
19+
node-version: 20
2020

21-
- uses: pnpm/action-setup@v2
21+
- uses: pnpm/action-setup@v4
2222
name: Install pnpm
2323
id: pnpm-install
2424
with:
25-
version: 8
25+
version: 9
2626
run_install: false
2727

2828
- name: Get pnpm store directory
@@ -31,7 +31,7 @@ jobs:
3131
run: |
3232
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
3333
34-
- uses: actions/cache@v3
34+
- uses: actions/cache@v4
3535
name: Setup pnpm cache
3636
with:
3737
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
@@ -46,7 +46,7 @@ jobs:
4646
run: pnpm build
4747

4848
- name: Publish
49-
uses: JS-DevTools/npm-publish@v1
50-
with:
51-
token: ${{ secrets.NPM_TOKEN }}
52-
access: public
49+
shell: bash
50+
run: |
51+
echo "//registry.npmjs.org/:_authToken="${{ secrets.NPM_TOKEN }}"" > ~/.npmrc
52+
pnpm publish --access public

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66

77
> ⚡️ A plugin for developing and building a Tampermonkey userscript based on [Vite](https://vitejs.dev).
88
9+
## Table of contents
10+
11+
- [Features](#features)
12+
- [Install](#install)
13+
- [Setup config](#setup-config)
14+
- [Using style modules](#using-style-modules)
15+
- [Plugin configuration](#plugin-configuration)
16+
917
## Features
1018

11-
- 🔥 Hot reloading after changing any files.
19+
- 🔥 Reloading page after changing any files.
1220
- 🔧 Configure Tampermonkey's Userscript header.
1321
- 💨 Import all [`grant`](https://www.tampermonkey.net/documentation.php#_grant)'s to the header by default in development mode.
1422
- 📝 Automatic addition of used [`grant`](https://www.tampermonkey.net/documentation.php#_grant)'s in the code when building for production.
@@ -28,7 +36,7 @@ yarn add vite-userscript-plugin -D
2836
pnpm add vite-userscript-plugin -D
2937
```
3038

31-
### Setup `vite.config.ts`
39+
### Setup config
3240

3341
```js
3442
import { defineConfig } from 'vite'
@@ -83,7 +91,19 @@ export default defineConfig((config) => {
8391
}
8492
```
8593

86-
## Plugin Configuration
94+
### Using style modules
95+
96+
```js
97+
import style from './style.css?raw'
98+
99+
// inject style element
100+
const styleElement = GM_addStyle(style)
101+
102+
// remove style element
103+
styleElement.remove()
104+
```
105+
106+
## Plugin configuration
87107

88108
```ts
89109
interface ServerConfig {

examples/basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "vite build"
99
},
1010
"devDependencies": {
11-
"sass": "1.59.2",
11+
"sass": "1.78.0",
1212
"vite-userscript-plugin": "workspace:*"
1313
}
1414
}

examples/basic/src/button.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import './styles/style.scss'
2-
31
export function createButton() {
42
const el = document.createElement('button')
53
el.textContent = 'Button'

examples/basic/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createButton } from './button.js'
2-
import './styles/style.css'
3-
import './styles/style.sass'
2+
import style from './style.scss?raw'
3+
4+
GM_addStyle(style)
45

56
const div = document.querySelector('div')!
67
div.appendChild(createButton())

examples/basic/src/style.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
text-decoration: underline;
3+
}

examples/basic/src/styles/style.css

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/basic/src/styles/style.sass

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/basic/src/styles/style.scss

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/basic/vite.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfig } from 'vite'
22
import Userscript from 'vite-userscript-plugin'
3+
34
import { name, version } from './package.json'
45

56
export default defineConfig((config) => {
@@ -14,8 +15,12 @@ export default defineConfig((config) => {
1415
},
1516
server: {
1617
port: 2000
18+
},
19+
esbuildTransformOptions: {
20+
minify: false
1721
}
1822
})
23+
1924
]
2025
}
2126
})

0 commit comments

Comments
 (0)