Skip to content

Commit b3cc236

Browse files
committed
feat(helper): splitting printing functions
1 parent 12915e2 commit b3cc236

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function watchConfigFile(): PluginOption {
88
name: 'storyblok-field-plugin-watch-config-file',
99
handleHotUpdate({ file, server }) {
1010
if (file.endsWith('field-plugin.config.json')) {
11-
printServerUrls(server)
11+
printSandboxUrl(server)
1212
}
1313
},
1414
}
@@ -40,6 +40,7 @@ export function printDev(): PluginOption {
4040
// Overrides the message that Vite prints out when the server is started. To reduce complexity, it does not include color
4141
server.printUrls = () => {
4242
printServerUrls(server)
43+
printSandboxUrl(server)
4344
}
4445
},
4546
}
@@ -62,11 +63,18 @@ function printServerUrls(server: ViteDevServer) {
6263
6364
${arrows.green} ${bold('Local')}: ${localUrl}
6465
${arrows.green} ${bold('Network')}: ${networkUrl}
65-
66-
See the plugin in action on
67-
68-
${arrows.green} ${bold('Sandbox')}: ${generateSandboxUrl(localUrl)}
6966
`)
7067
}
7168

69+
function printSandboxUrl(server: ViteDevServer) {
70+
if (!server.resolvedUrls) {
71+
return
72+
}
73+
const localUrl = server.resolvedUrls.local[0]
74+
75+
console.log(` See the plugin in action on
76+
77+
${arrows.green} ${bold('Sandbox')}: ${generateSandboxUrl(localUrl)}`)
78+
}
79+
7280
export const plugins = [printProd(), printDev(), watchConfigFile()]

0 commit comments

Comments
 (0)