Skip to content

Commit

Permalink
fix(plugin-vite): get vite dev url
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcherGu committed May 14, 2024
1 parent 8bae3c7 commit 6916b28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions packages/plugin-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AddressInfo } from 'node:net'
import type { PluginOption, ResolvedConfig } from 'vite'
import type { ElectronConfig, InlineConfig } from '@doubleshot/builder'
import { build, dev } from '@doubleshot/builder'
Expand Down Expand Up @@ -46,16 +45,15 @@ export function VitePluginDoubleshot(userConfig: Partial<VitePluginDoubleshotCon
await configureForMode(resolvedConfig)
},
configureServer(server) {
server?.httpServer?.on('listening', async () => {
if (server.httpServer && !userConfig.rendererUrl) {
const { address, port, family } = server.httpServer.address() as AddressInfo
if (family === 'IPv6')
userConfig.rendererUrl = `http://[${address}]:${port}`

else
userConfig.rendererUrl = `http://${address}:${port}`
}
const printUrls = server.printUrls.bind(server)
// override printUrls to get rendererUrl
server.printUrls = () => {
printUrls()
if (!userConfig.rendererUrl)
userConfig.rendererUrl = server.resolvedUrls!.local[0]
}

server?.httpServer?.on('listening', async () => {
await dev(userConfig)
})
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vite/test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function createWindow() {
console.log(msg);
import_electron.app.quit();
});
const URL = isDev ? "http://127.0.0.1:12345" : \`file://\${(0, import_node_path.join)(import_electron.app.getAppPath(), "dist/renderer/index.html")}\`;
const URL = isDev ? "http://127.0.0.1:12345/" : \`file://\${(0, import_node_path.join)(import_electron.app.getAppPath(), "dist/renderer/index.html")}\`;
win.loadURL(URL);
}
import_electron.app.whenReady().then(() => {
Expand Down

0 comments on commit 6916b28

Please sign in to comment.