Skip to content

Commit 0a0bbf4

Browse files
committed
feat(helper): watching config files for changes
1 parent 978e380 commit 0a0bbf4

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

packages/field-plugin/helpers/vite/src/plugins.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
import type { PluginOption } from 'vite'
1+
import type { PluginOption, ViteDevServer } from 'vite'
22
import { generateSandboxUrl } from './sandbox'
33
import { bold, green } from './utils/text'
44
import { arrows } from './utils/arrows'
55

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+
617
export function printProd(): PluginOption {
718
return {
819
name: 'storyblok-field-plugin-print-prod',
@@ -28,13 +39,20 @@ export function printDev(): PluginOption {
2839
configureServer(server) {
2940
// Overrides the message that Vite prints out when the server is started. To reduce complexity, it does not include color
3041
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]
3654

37-
console.log(`
55+
console.log(`
3856
${arrows.green} ${bold(
3957
'Partner Portal',
4058
)}: https://app.storyblok.com/#/partner/fields
@@ -49,9 +67,6 @@ export function printDev(): PluginOption {
4967
5068
${arrows.green} ${bold('Sandbox')}: ${generateSandboxUrl(localUrl)}
5169
`)
52-
}
53-
},
54-
}
5570
}
5671

57-
export const plugins = [printProd(), printDev()]
72+
export const plugins = [printProd(), printDev(), watchConfigFile()]

0 commit comments

Comments
 (0)