Skip to content

Commit 4e74723

Browse files
Tahulfarnabaz
authored andcommitted
feat(config): allow ws config (#1249)
* feat(config): allow ws config * feat(ws): allow ws configuration from `watch` key * chore(playground): prune playground content
1 parent 17ecfea commit 4e74723

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

docs/content/4.api/3.configuration.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export default defineNuxtConfig({
1616
})
1717
```
1818

19-
2019
## `base`
2120

2221
- Type: `String`{lang=ts}
@@ -34,18 +33,44 @@ export default defineNuxtConfig({
3433

3534
## `watch`
3635

37-
- Type: `Boolean`{lang=ts}
38-
- Default: `true`{lang=ts}
36+
- Type: `Object | false`{lang=ts}
37+
- Default: `{ port: 4000, showUrl: true }`{lang=ts}
3938

40-
Disable content watcher and hot content reload. Watcher is a development feature and will not includes in the production.
39+
Disable content watcher and hot content reload.
4140

42-
```ts [nuxt.config.ts]
43-
export default defineNuxtConfig({
44-
content: {
45-
watch: true
46-
}
47-
})
48-
```
41+
The watcher is a development feature and will not be included in production.
42+
43+
::code-group
44+
45+
```ts [Enabled]
46+
export default defineNuxtConfig({
47+
content: {
48+
watch: {
49+
ws: {
50+
port: 4000,
51+
showUrl: true
52+
}
53+
}
54+
}
55+
})
56+
```
57+
58+
```ts [Disabled]
59+
export default defineNuxtConfig({
60+
content: {
61+
watch: false
62+
}
63+
})
64+
```
65+
66+
::
67+
68+
### `ws` options
69+
70+
| Option | Default | Description |
71+
| ----------------- | :--------: | :-------- |
72+
| `port` | `4000` | Select the port used for the WebSocket server. |
73+
| `showUrl` | `false` | Toggle URL display in dev server boot message. |
4974

5075
## `sources`
5176

@@ -179,7 +204,7 @@ Nuxt Content uses [Shiki](https://github.com/shikijs/shiki) to provide syntax hi
179204

180205
### `highlight` options
181206

182-
| Option | Default | Description |
207+
| Option | Type | Description |
183208
| ----------------- | :--------: | :-------- |
184209
| `theme` | `ShikiTheme` | The [color theme](https://github.com/shikijs/shiki/blob/main/docs/themes.md) to use |
185210
| `preload` | `ShikiLang[]` | The [preloaded languages](https://github.com/shikijs/shiki/blob/main/docs/languages.md) available for highlighting. |

playground/pages/sandbox.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@
2222
</div>
2323
</template>
2424
</ContentDoc>
25-
26-
<ContentList />
2725
</div>
2826
</template>

src/module.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
useLogger,
1111
addTemplate
1212
} from '@nuxt/kit'
13+
import type { ListenOptions } from 'listhen'
1314
// eslint-disable-next-line import/no-named-as-default
1415
import defu from 'defu'
1516
import { hash } from 'ohash'
@@ -48,7 +49,9 @@ export interface ModuleOptions {
4849
*
4950
* @default true
5051
*/
51-
watch: boolean
52+
watch: false | {
53+
ws: Partial<ListenOptions>
54+
}
5255
/**
5356
* Contents can located in multiple places, in multiple directories or even in remote git repositories.
5457
* Using sources option you can tell Content module where to look for contents.
@@ -180,7 +183,12 @@ export default defineNuxtModule<ModuleOptions>({
180183
},
181184
defaults: {
182185
base: '_content',
183-
watch: true,
186+
watch: {
187+
ws: {
188+
port: 4000,
189+
showURL: false
190+
}
191+
},
184192
sources: ['content'],
185193
ignores: ['\\.', '-'],
186194
locales: [],
@@ -403,11 +411,11 @@ export default defineNuxtModule<ModuleOptions>({
403411
}
404412

405413
// Setup content dev module
406-
if (!nuxt.options.dev || !options.watch) {
407-
return
408-
}
414+
if (!nuxt.options.dev) { return }
409415

410416
nuxt.hook('nitro:init', async (nitro) => {
417+
if (!options.watch || !options.watch.ws) { return }
418+
411419
const ws = createWebSocket()
412420

413421
// Dispose storage on nuxt close
@@ -416,7 +424,8 @@ export default defineNuxtModule<ModuleOptions>({
416424
})
417425

418426
// Listen dev server
419-
const { server, url } = await listen(() => 'Nuxt Content', { port: 4000, showURL: false })
427+
const { server, url } = await listen(() => 'Nuxt Content', options.watch.ws)
428+
420429
server.on('upgrade', ws.serve)
421430

422431
// Register ws url

0 commit comments

Comments
 (0)