Skip to content

Commit 1b2bcb1

Browse files
committed
feat: remove css injecting
1 parent 2b526bd commit 1b2bcb1

File tree

16 files changed

+2072
-1800
lines changed

16 files changed

+2072
-1800
lines changed

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default defineConfig((config) => {
1414
},
1515
server: {
1616
port: 2000
17+
},
18+
esbuildTransformOptions: {
19+
minify: false
1720
}
1821
})
1922
]

0 commit comments

Comments
 (0)