1
- import type { PluginOption } from 'vite'
1
+ import type { PluginOption , ViteDevServer } from 'vite'
2
2
import { generateSandboxUrl } from './sandbox'
3
3
import { bold , green } from './utils/text'
4
4
import { arrows } from './utils/arrows'
5
5
6
+ export function watchConfigFile ( ) : PluginOption {
7
+ return {
8
+ name : 'storyblok-field-plugin-watch-config-file' ,
9
+ handleHotUpdate ( { file, server } ) {
10
+ if ( file . endsWith ( 'field-plugin.config.json' ) ) {
11
+ printServerUrls ( server )
12
+ }
13
+ } ,
14
+ }
15
+ }
16
+
6
17
export function printProd ( ) : PluginOption {
7
18
return {
8
19
name : 'storyblok-field-plugin-print-prod' ,
@@ -28,13 +39,20 @@ export function printDev(): PluginOption {
28
39
configureServer ( server ) {
29
40
// Overrides the message that Vite prints out when the server is started. To reduce complexity, it does not include color
30
41
server . printUrls = ( ) => {
31
- if ( ! server . resolvedUrls ) {
32
- return
33
- }
34
- const localUrl = server . resolvedUrls . local [ 0 ]
35
- const networkUrl = server . resolvedUrls . network [ 0 ]
42
+ printServerUrls ( server )
43
+ }
44
+ } ,
45
+ }
46
+ }
47
+
48
+ function printServerUrls ( server : ViteDevServer ) {
49
+ if ( ! server . resolvedUrls ) {
50
+ return
51
+ }
52
+ const localUrl = server . resolvedUrls . local [ 0 ]
53
+ const networkUrl = server . resolvedUrls . network [ 0 ]
36
54
37
- console . log ( `
55
+ console . log ( `
38
56
${ arrows . green } ${ bold (
39
57
'Partner Portal' ,
40
58
) } : https://app.storyblok.com/#/partner/fields
@@ -49,9 +67,6 @@ export function printDev(): PluginOption {
49
67
50
68
${ arrows . green } ${ bold ( 'Sandbox' ) } : ${ generateSandboxUrl ( localUrl ) }
51
69
` )
52
- }
53
- } ,
54
- }
55
70
}
56
71
57
- export const plugins = [ printProd ( ) , printDev ( ) ]
72
+ export const plugins = [ printProd ( ) , printDev ( ) , watchConfigFile ( ) ]
0 commit comments