@ui-doc/vite 0.3.0 → 0.3.2

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 CHANGED
@@ -1,10 +1,21 @@
1
- # UI-Doc vite plugin
1
+ # @ui-doc/vite
2
2
 
3
- Integrates UI-Doc into vite by using the `@ui-doc/rollup` plugin and add functionality to vite dev server to display / preview the UI-Doc. Per default it will add a `ui-doc` uri to your vite dev url. You can change the uri by changing the `output.dir` or `output.baseUri` option.
3
+ A Vite plugin for generating interactive UI documentation from JSDoc-style comment blocks in your source files. This plugin integrates UI-Doc into your Vite build process and adds a live development server with hot-reload support.
4
4
 
5
- ## Install
5
+ ## Overview
6
6
 
7
- ```sh
7
+ The Vite plugin wraps the [@ui-doc/rollup](../rollup/README.md) plugin and adds Vite-specific functionality:
8
+
9
+ - Serve UI-Doc documentation via the Vite dev server
10
+ - Live reload when documentation changes
11
+ - Automatic asset handling and injection
12
+ - Support for Vite's build pipeline
13
+
14
+ By default, your documentation is served at `/ui-doc/` during development. The base URI can be customized via the `output.baseUri` option.
15
+
16
+ ## Installation
17
+
18
+ ```bash
8
19
  # npm
9
20
  npm install --save-dev @ui-doc/vite @ui-doc/html-renderer @highlightjs/cdn-assets
10
21
 
@@ -15,7 +26,59 @@ yarn add --dev @ui-doc/vite @ui-doc/html-renderer @highlightjs/cdn-assets
15
26
  pnpm install --save-dev @ui-doc/vite @ui-doc/html-renderer @highlightjs/cdn-assets
16
27
  ```
17
28
 
18
- ## Setup
29
+ **Requirements:**
30
+
31
+ - Node.js >= 16.0.0
32
+ - Vite >= 5.0.0
33
+
34
+ ## Quick Start
35
+
36
+ Add the plugin to your `vite.config.js`:
37
+
38
+ ```js
39
+ import uidoc from '@ui-doc/vite'
40
+ import { defineConfig } from 'vite'
41
+
42
+ export default defineConfig({
43
+ plugins: [
44
+ uidoc({
45
+ source: ['src/**/*.css'],
46
+ settings: {
47
+ texts: {
48
+ title: 'My Component Library',
49
+ },
50
+ },
51
+ }),
52
+ ],
53
+ })
54
+ ```
55
+
56
+ Start the dev server:
57
+
58
+ ```bash
59
+ vite
60
+ ```
61
+
62
+ Your documentation will be available at `http://localhost:5173/ui-doc/`
63
+
64
+ ## Basic Configuration
65
+
66
+ ### Minimal Setup
67
+
68
+ ```js
69
+ import uidoc from '@ui-doc/vite'
70
+ import { defineConfig } from 'vite'
71
+
72
+ export default defineConfig({
73
+ plugins: [
74
+ uidoc({
75
+ source: ['css/**/*.css', 'js/**/*.js'],
76
+ }),
77
+ ],
78
+ })
79
+ ```
80
+
81
+ ### With Custom Settings
19
82
 
20
83
  ```js
21
84
  import uidoc from '@ui-doc/vite'
@@ -23,7 +86,7 @@ import { defineConfig } from 'vite'
23
86
 
24
87
  export default defineConfig({
25
88
  build: {
26
- outDir: 'dist/vite',
89
+ outDir: 'dist',
27
90
  rollupOptions: {
28
91
  input: {
29
92
  app: 'css/index.css',
@@ -35,17 +98,18 @@ export default defineConfig({
35
98
  uidoc({
36
99
  settings: {
37
100
  generate: {
38
- logo: () => 'Vite',
101
+ logo: () => 'My Component Library',
39
102
  },
40
103
  texts: {
41
- title: 'Vite Example',
104
+ title: 'Component Documentation',
105
+ copyright: '© 2025 My Company',
42
106
  },
43
107
  },
44
108
  source: ['css/**/*.css'],
45
109
  assets: {
46
110
  example: {
47
111
  name: 'app',
48
- input: true,
112
+ fromInput: true,
49
113
  },
50
114
  },
51
115
  }),
@@ -53,15 +117,140 @@ export default defineConfig({
53
117
  })
54
118
  ```
55
119
 
56
- ## Options
120
+ ## Assets Configuration
121
+
122
+ ### Include Styles and Scripts
123
+
124
+ You can include custom CSS and JavaScript in your documentation pages and examples:
125
+
126
+ ```js
127
+ uidoc({
128
+ source: ['css/**/*.css'],
129
+ assets: {
130
+ // Static assets folder (copied to output)
131
+ static: './assets',
132
+
133
+ // Custom styles/scripts for documentation pages
134
+ page: [
135
+ {
136
+ name: 'custom-ui-doc',
137
+ fromInput: true, // Asset defined in Vite's input
138
+ },
139
+ ],
140
+
141
+ // Custom styles/scripts for example previews
142
+ example: [
143
+ {
144
+ name: 'app',
145
+ fromInput: true,
146
+ attrs: {
147
+ type: 'module', // Add custom HTML attributes
148
+ },
149
+ },
150
+ ],
151
+ },
152
+ })
153
+ ```
154
+
155
+ ### Asset Options
57
156
 
58
- Please see the Options from `@ui-doc/rollup` they are the same.
157
+ Assets can be loaded from different sources:
59
158
 
60
- # Good to Know
159
+ ```text
160
+ {
161
+ // Load from Vite's input configuration
162
+ name: 'app',
163
+ fromInput: true,
61
164
 
62
- ## The `output.baseUri` setting can be changed depending on context
165
+ // Or load from a file
166
+ name: 'custom.css',
167
+ file: './path/to/custom.css',
63
168
 
64
- When using vite serve and build with same setting and you want to extract the UI-Doc into a other system you need to change the `output.baseUri` depending on build context. UI-Doc in vite will set the `output.dir` per default to `ui-doc` so it can run correctly while serving but you may don't want the `ui-doc` uri in your final output.
169
+ // Or load from node_modules
170
+ name: 'library.js',
171
+ dependency: 'some-library/dist/library.js',
172
+
173
+ // Or provide source directly
174
+ name: 'inline.css',
175
+ source: 'body { margin: 0; }',
176
+
177
+ // Add HTML attributes
178
+ attrs: {
179
+ type: 'module',
180
+ defer: 'true',
181
+ },
182
+ }
183
+ ```
184
+
185
+ ## Output Configuration
186
+
187
+ ### Change Output Directory
188
+
189
+ ```js
190
+ uidoc({
191
+ source: ['css/**/*.css'],
192
+ output: {
193
+ dir: 'docs', // Output to dist/docs instead of dist/ui-doc
194
+ },
195
+ })
196
+ ```
197
+
198
+ ### Change Base URI
199
+
200
+ ```js
201
+ uidoc({
202
+ source: ['css/**/*.css'],
203
+ output: {
204
+ baseUri: '/documentation/', // Serve at /documentation/ instead of /ui-doc/
205
+ },
206
+ })
207
+ ```
208
+
209
+ ### Relative URLs for Build
210
+
211
+ ```js
212
+ uidoc({
213
+ source: ['css/**/*.css'],
214
+ output: {
215
+ baseUri: '.', // Use relative URLs in build output
216
+ },
217
+ })
218
+ ```
219
+
220
+ ## Advanced Configuration
221
+
222
+ ### Custom Templates
223
+
224
+ Override default templates or add custom ones:
225
+
226
+ ```js
227
+ uidoc({
228
+ source: ['css/**/*.css'],
229
+ templatePath: 'ui-doc/templates', // Directory with custom templates
230
+ })
231
+ ```
232
+
233
+ ### Conditional Configuration
234
+
235
+ Configure the plugin differently for dev and build:
236
+
237
+ ```js
238
+ export default defineConfig(({ command }) => {
239
+ return {
240
+ plugins: [
241
+ uidoc({
242
+ source: ['css/**/*.css'],
243
+ output: {
244
+ // Use absolute path in dev, relative in build
245
+ baseUri: command === 'serve' ? undefined : '.',
246
+ },
247
+ }),
248
+ ],
249
+ }
250
+ })
251
+ ```
252
+
253
+ ### Complete Example
65
254
 
66
255
  ```js
67
256
  import uidoc from '@ui-doc/vite'
@@ -70,30 +259,264 @@ import { defineConfig } from 'vite'
70
259
  export default defineConfig(({ command }) => {
71
260
  return {
72
261
  build: {
73
- outDir: 'dist/vite',
262
+ outDir: 'dist',
74
263
  rollupOptions: {
75
264
  input: {
76
- app: 'css/index.css',
77
- 'ui-doc-custom': 'css/ui-doc.css',
265
+ 'app': 'js/app.js',
266
+ 'ui-doc-custom': 'ui-doc/custom.css',
78
267
  },
79
268
  },
80
269
  },
270
+
81
271
  plugins: [
82
272
  uidoc({
83
- source: ['css/**/*.css'],
273
+ // Source files to parse
274
+ source: ['css/**/*.css', 'js/**/*.js'],
275
+
276
+ // Output configuration
277
+ output: {
278
+ dir: 'ui-doc',
279
+ baseUri: command === 'serve' ? undefined : '.',
280
+ },
281
+
282
+ // Custom templates
283
+ templatePath: 'ui-doc/templates',
284
+
285
+ // UI-Doc settings
286
+ settings: {
287
+ generate: {
288
+ logo: () => '<img src="logo.svg" alt="Logo">',
289
+ footerText: () => '© 2025 My Company',
290
+ },
291
+ texts: {
292
+ title: 'Component Library',
293
+ copyright: '© 2025 My Company',
294
+ },
295
+ },
296
+
297
+ // Assets
84
298
  assets: {
85
- output: {
86
- baseUri: command === 'serve' ? undefined : '.',
87
- }
88
- staticAssets: './assets',
89
- page: {
90
- name: 'ui-doc-custom'
91
- input: true
92
- }
93
- example: {
299
+ static: './ui-doc/assets',
300
+ page: [
301
+ {
302
+ name: 'ui-doc-custom',
303
+ fromInput: true,
304
+ },
305
+ ],
306
+ example: [
307
+ {
308
+ name: 'app',
309
+ fromInput: true,
310
+ attrs: {
311
+ type: 'module',
312
+ },
313
+ },
314
+ ],
315
+ },
316
+ }),
317
+ ],
318
+ }
319
+ })
320
+ ```
321
+
322
+ ## Plugin Options
323
+
324
+ All options from [@ui-doc/rollup](../rollup/README.md#options) are supported. The Vite plugin adds the following defaults:
325
+
326
+ | Name | Type | Default | Description |
327
+ | ---------- | ------ | ---------- | ------------------------------------------------ |
328
+ | output.dir | string | `'ui-doc'` | Output directory (relative to Vite's output dir) |
329
+
330
+ ### Core Options Summary
331
+
332
+ | Name | Type | Required | Description |
333
+ | ------------ | --------------- | -------- | -------------------------------------------- |
334
+ | source | string[] | yes | Glob patterns to find source files |
335
+ | output | object | no | Output configuration (dir, baseUri) |
336
+ | settings | object | no | UI-Doc settings (generate, texts) |
337
+ | assets | object | no | Asset configuration (static, page, example) |
338
+ | templatePath | string | no | Custom template directory |
339
+ | renderer | Renderer | no | Custom renderer instance |
340
+ | blockParser | BlockParser | no | Custom block parser instance |
341
+
342
+ See the [@ui-doc/rollup documentation](../rollup/README.md#options) for detailed option descriptions.
343
+
344
+ ## Development Server
345
+
346
+ When running `vite` or `vite dev`, the plugin adds a development server that:
347
+
348
+ 1. Serves documentation at `/{output.dir}/` (default: `/ui-doc/`)
349
+ 2. Hot-reloads when documentation changes
350
+ 3. Injects Vite's client script for HMR
351
+ 4. Serves static assets from the configured static folder
352
+
353
+ The plugin logs the documentation URL on server start:
354
+
355
+ ```text
356
+ UI-Doc v0.3.1 under /ui-doc/
357
+
358
+ ➜ Local: http://localhost:5173/ui-doc/
359
+ ```
360
+
361
+ ## Build Output
362
+
363
+ When running `vite build`, the plugin:
364
+
365
+ 1. Generates documentation files in `{outDir}/{output.dir}/`
366
+ 2. Copies static assets to the output directory
367
+ 3. Resolves and bundles all CSS/JS assets from Vite's input
368
+
369
+ Example output structure:
370
+
371
+ ```text
372
+ dist/
373
+ ├── assets/
374
+ │ ├── app-abc123.js
375
+ │ └── app-abc123.css
376
+ └── ui-doc/
377
+ ├── index.html
378
+ ├── components.html
379
+ ├── examples/
380
+ │ └── button.html
381
+ ├── assets/
382
+ │ └── (static assets)
383
+ └── (other documentation files)
384
+ ```
385
+
386
+ ## Writing Documentation
387
+
388
+ UI-Doc uses JSDoc-style comment blocks with special tags. See the [@ui-doc/core documentation](../core/README.md) for the complete documentation syntax.
389
+
390
+ ### Quick Example
391
+
392
+ ```css
393
+ /**
394
+ * @page buttons Buttons
395
+ */
396
+
397
+ /**
398
+ * A primary button for main actions.
399
+ *
400
+ * @location buttons.primary Primary Button
401
+ * @example
402
+ * <button class="btn btn-primary">Click Me</button>
403
+ */
404
+ .btn-primary {
405
+ background: blue;
406
+ color: white;
407
+ padding: 10px 20px;
408
+ border: none;
409
+ border-radius: 4px;
410
+ }
411
+ ```
412
+
413
+ ## Common Patterns
414
+
415
+ ### Pattern 1: Standalone Documentation
416
+
417
+ Build UI-Doc independently from your main application:
418
+
419
+ ```js
420
+ export default defineConfig({
421
+ build: {
422
+ outDir: 'docs',
423
+ rollupOptions: {
424
+ input: {
425
+ styles: 'ui-doc/styles.css',
426
+ },
427
+ },
428
+ },
429
+
430
+ plugins: [
431
+ uidoc({
432
+ source: ['src/**/*.css'],
433
+ output: {
434
+ dir: '.', // Output directly to docs/
435
+ baseUri: '.',
436
+ },
437
+ assets: {
438
+ static: './ui-doc/assets',
439
+ page: [
440
+ {
441
+ name: 'styles',
442
+ fromInput: true,
443
+ },
444
+ ],
445
+ },
446
+ }),
447
+ ],
448
+ })
449
+ ```
450
+
451
+ ### Pattern 2: Integrated Documentation
452
+
453
+ Include UI-Doc alongside your application build:
454
+
455
+ ```js
456
+ export default defineConfig({
457
+ build: {
458
+ outDir: 'dist',
459
+ rollupOptions: {
460
+ input: {
461
+ app: 'src/main.js',
462
+ },
463
+ },
464
+ },
465
+
466
+ plugins: [
467
+ uidoc({
468
+ source: ['src/**/*.css'],
469
+ output: {
470
+ dir: 'ui-doc', // dist/ui-doc/
471
+ },
472
+ assets: {
473
+ example: [
474
+ {
94
475
  name: 'app',
95
- input: true,
476
+ fromInput: true,
96
477
  },
478
+ ],
479
+ },
480
+ }),
481
+ ],
482
+ })
483
+ ```
484
+
485
+ ### Pattern 3: Multiple Input Entries
486
+
487
+ Use multiple Vite inputs for custom documentation styling:
488
+
489
+ ```js
490
+ export default defineConfig(({ command }) => {
491
+ return {
492
+ build: {
493
+ rollupOptions: {
494
+ input: {
495
+ 'app': 'src/main.js',
496
+ 'ui-doc-theme': 'ui-doc/theme.css',
497
+ },
498
+ },
499
+ },
500
+
501
+ plugins: [
502
+ uidoc({
503
+ source: ['src/**/*.css'],
504
+ output: {
505
+ baseUri: command === 'serve' ? undefined : '.',
506
+ },
507
+ assets: {
508
+ page: [
509
+ {
510
+ name: 'ui-doc-theme',
511
+ fromInput: true,
512
+ },
513
+ ],
514
+ example: [
515
+ {
516
+ name: 'app',
517
+ fromInput: true,
518
+ },
519
+ ],
97
520
  },
98
521
  }),
99
522
  ],
@@ -101,4 +524,85 @@ export default defineConfig(({ command }) => {
101
524
  })
102
525
  ```
103
526
 
104
- # Known Issues
527
+ ## Troubleshooting
528
+
529
+ ### Documentation Not Showing in Dev Server
530
+
531
+ Make sure you don't set `output.baseUri` to `'.'` in dev mode:
532
+
533
+ ```js
534
+ // This will break dev server
535
+ uidoc({ output: { baseUri: '.' } })
536
+
537
+ // Use conditional configuration instead
538
+ uidoc({
539
+ output: {
540
+ baseUri: command === 'serve' ? undefined : '.',
541
+ },
542
+ })
543
+ ```
544
+
545
+ ### Assets Not Loading
546
+
547
+ Ensure assets are registered correctly:
548
+
549
+ ```text
550
+ // If using Vite's input configuration
551
+ {
552
+ name: 'app', // Must match the key in rollupOptions.input
553
+ fromInput: true,
554
+ }
555
+
556
+ // If using a file path
557
+ {
558
+ name: 'custom.css',
559
+ file: './path/to/custom.css', // Relative to project root
560
+ }
561
+ ```
562
+
563
+ ### Hot Reload Not Working
564
+
565
+ The plugin automatically watches your source files for changes. If hot reload isn't working:
566
+
567
+ 1. Check that your `source` glob patterns are correct
568
+ 2. Verify that Vite is watching the files (check Vite config)
569
+ 3. Try restarting the dev server
570
+
571
+ ## API
572
+
573
+ ### Plugin Export
574
+
575
+ ```ts
576
+ export default function uidocPlugin(options: Options): Promise<Plugin<Api>>
577
+ ```
578
+
579
+ ### Options Type
580
+
581
+ ```ts
582
+ import type { Options as RollupPluginOptions } from '@ui-doc/rollup'
583
+
584
+ export type Options = RollupPluginOptions
585
+ ```
586
+
587
+ See [@ui-doc/rollup API documentation](../rollup/README.md#options) for the complete options reference.
588
+
589
+ ### API Type
590
+
591
+ ```ts
592
+ import type { Api as RollupPluginApi } from '@ui-doc/rollup'
593
+
594
+ export interface Api extends RollupPluginApi {
595
+ version: string
596
+ }
597
+ ```
598
+
599
+ ## Related Packages
600
+
601
+ - [@ui-doc/core](../core/README.md) - Core parsing and rendering engine
602
+ - [@ui-doc/rollup](../rollup/README.md) - Rollup plugin (wrapped by this plugin)
603
+ - [@ui-doc/html-renderer](../html-renderer/README.md) - Default HTML renderer
604
+ - [@ui-doc/node](../node/README.md) - File system utilities
605
+
606
+ ## License
607
+
608
+ See [LICENSE.md](../../LICENSE.md) for license information.