-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow using vite as a proxy for another vite server (#13218)
Co-authored-by: sapphi-red <[email protected]>
- Loading branch information
1 parent
eb75103
commit 711dd80
Showing
12 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { test } from 'vitest' | ||
import { editFile, page, untilUpdated, viteTestUrl } from '~utils' | ||
|
||
test('proxy-hmr', async () => { | ||
await page.goto(viteTestUrl) | ||
const otherAppTextLocator = page.frameLocator('iframe').locator('.content') | ||
await untilUpdated(() => otherAppTextLocator.textContent(), 'other app') | ||
editFile('other-app/index.html', (code) => | ||
code.replace('app', 'modified app'), | ||
) | ||
await untilUpdated( | ||
() => otherAppTextLocator.textContent(), | ||
'other modified app', | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// this is automatically detected by playground/vitestSetup.ts and will replace | ||
// the default e2e test serve behavior | ||
|
||
import path from 'node:path' | ||
import { rootDir, setViteUrl } from '~utils' | ||
|
||
export async function serve(): Promise<{ close(): Promise<void> }> { | ||
const vite = await import('vite') | ||
const rootServer = await vite.createServer({ | ||
root: rootDir, | ||
logLevel: 'silent', | ||
}) | ||
const otherServer = await vite.createServer({ | ||
root: path.join(rootDir, 'other-app'), | ||
logLevel: 'silent', | ||
}) | ||
|
||
await Promise.all([rootServer.listen(), otherServer.listen()]) | ||
const viteUrl = rootServer.resolvedUrls.local[0] | ||
setViteUrl(viteUrl) | ||
|
||
return { | ||
async close() { | ||
await Promise.all([rootServer.close(), otherServer.close()]) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
root app<br /> | ||
<iframe src="/anotherApp" style="border: 0"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<span class="content">other app</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@vitejs/test-other-app", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
base: '/anotherApp', | ||
server: { | ||
port: 9607, | ||
strictPort: true, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@vitejs/test-proxy-hmr", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
server: { | ||
port: 9606, | ||
proxy: { | ||
'/anotherApp': { | ||
target: 'http://localhost:9607', | ||
ws: true, | ||
}, | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.