mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 03:26:22 +00:00
feat: support configurable ws port and remote development (#429)
Co-authored-by: Jeremy Press <jeremy@replit.com> Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com>
This commit is contained in:
parent
4b89202f7e
commit
b6b1dabde0
5 changed files with 22 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,3 +7,5 @@ tsconfig.tsbuildinfo
|
||||||
.obsidian
|
.obsidian
|
||||||
.quartz-cache
|
.quartz-cache
|
||||||
private/
|
private/
|
||||||
|
.replit
|
||||||
|
replit.nix
|
||||||
|
|
|
@ -76,6 +76,16 @@ export const BuildArgv = {
|
||||||
default: 8080,
|
default: 8080,
|
||||||
describe: "port to serve Quartz on",
|
describe: "port to serve Quartz on",
|
||||||
},
|
},
|
||||||
|
wsPort: {
|
||||||
|
number: true,
|
||||||
|
default: 3001,
|
||||||
|
describe: "port to use for WebSocket-based hot-reload notifications",
|
||||||
|
},
|
||||||
|
remoteDevHost: {
|
||||||
|
string: true,
|
||||||
|
default: "",
|
||||||
|
describe: "A URL override for the websocket connection if you are not developing on localhost",
|
||||||
|
},
|
||||||
bundleInfo: {
|
bundleInfo: {
|
||||||
boolean: true,
|
boolean: true,
|
||||||
default: false,
|
default: false,
|
||||||
|
|
|
@ -402,7 +402,7 @@ export async function handleBuild(argv) {
|
||||||
return serve()
|
return serve()
|
||||||
})
|
})
|
||||||
server.listen(argv.port)
|
server.listen(argv.port)
|
||||||
const wss = new WebSocketServer({ port: 3001 })
|
const wss = new WebSocketServer({ port: argv.wsPort })
|
||||||
wss.on("connection", (ws) => connections.push(ws))
|
wss.on("connection", (ws) => connections.push(ws))
|
||||||
console.log(
|
console.log(
|
||||||
chalk.cyan(
|
chalk.cyan(
|
||||||
|
|
|
@ -107,12 +107,18 @@ function addGlobalPageResources(
|
||||||
document.dispatchEvent(event)`)
|
document.dispatchEvent(event)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let wsUrl = `ws://localhost:${ctx.argv.wsPort}`
|
||||||
|
|
||||||
|
if (ctx.argv.remoteDevHost) {
|
||||||
|
wsUrl = `wss://${ctx.argv.remoteDevHost}:${ctx.argv.wsPort}`
|
||||||
|
}
|
||||||
|
|
||||||
if (reloadScript) {
|
if (reloadScript) {
|
||||||
staticResources.js.push({
|
staticResources.js.push({
|
||||||
loadTime: "afterDOMReady",
|
loadTime: "afterDOMReady",
|
||||||
contentType: "inline",
|
contentType: "inline",
|
||||||
script: `
|
script: `
|
||||||
const socket = new WebSocket('ws://localhost:3001')
|
const socket = new WebSocket('${wsUrl}'')
|
||||||
socket.addEventListener('message', () => document.location.reload())
|
socket.addEventListener('message', () => document.location.reload())
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,6 +7,8 @@ export interface Argv {
|
||||||
output: string
|
output: string
|
||||||
serve: boolean
|
serve: boolean
|
||||||
port: number
|
port: number
|
||||||
|
wsPort: number
|
||||||
|
remoteDevHost?: string
|
||||||
concurrency?: number
|
concurrency?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue