Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support mpa #12

Open
wants to merge 3 commits into
base: refactor-rolldown-module-factory
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/vite/src/node/server/environments/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,26 +279,29 @@ class RolldownEnvironment extends DevEnvironment {
...this.inputOptions,
output: this.outputOptions,
})
this.result = await this.instance.build()
this.fileModuleIds = new Set(
this.result.output[0].moduleIds.map((id) => cleanUrl(id)),
)
await this.buildInner()

this.buildTimestamp = Date.now()
console.timeEnd(`[rolldown:${this.name}:build]`)
}

async buildInner() {
this.result = await this.instance.build()
this.fileModuleIds = new Set(
this.result.output
.flatMap((c) => (c.type === 'chunk' ? c.moduleIds : []))
.map((id) => cleanUrl(id)),
)
}

async buildHmr(
file: string,
): Promise<rolldown.RolldownOutputChunk | undefined> {
logger.info(`hmr '${file}'`, { timestamp: true })
console.time(`[rolldown:${this.name}:rebuild]`)
const result = await this.instance.build()
this.fileModuleIds = new Set(
this.result.output[0].moduleIds.map((id) => cleanUrl(id)),
)
await this.buildInner()
console.timeEnd(`[rolldown:${this.name}:rebuild]`)
const chunk = result.output.find(
const chunk = this.result.output.find(
(v) => v.type === 'chunk' && v.name === 'hmr-update',
)
if (chunk) {
Expand Down
11 changes: 11 additions & 0 deletions playground/rolldown-dev-mpa/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test } from 'vitest'
import { page } from '../../test-utils'

test('basic', async () => {
await page.getByRole('heading', { name: 'Home' }).click()
await page.getByText('Rendered by /index.js').click()
await page.getByRole('link', { name: 'About' }).click()
await page.waitForURL(/\/about/)
await page.getByRole('heading', { name: 'About' }).click()
await page.getByText('Rendered by /about/index.js').click()
})
15 changes: 15 additions & 0 deletions playground/rolldown-dev-mpa/about/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head></head>
<body>
<div>
<h1>About</h1>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</div>
<div id="root"></div>
<script type="module" src="./index.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions playground/rolldown-dev-mpa/about/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
document.getElementById('root').innerHTML = `
<p>Rendered by /about/index.js: ${Math.random().toString(36).slice(2)}</p>
`
15 changes: 15 additions & 0 deletions playground/rolldown-dev-mpa/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head></head>
<body>
<div>
<h1>Home</h1>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
<div id="root"></div>
<script type="module" src="./index.js"></script>
</div>
</body>
</html>
3 changes: 3 additions & 0 deletions playground/rolldown-dev-mpa/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
document.getElementById('root').innerHTML = `
<p>Rendered by /index.js: ${Math.random().toString(36).slice(2)}</p>
`
10 changes: 10 additions & 0 deletions playground/rolldown-dev-mpa/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@vitejs/test-rolldown-dev-mpa",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
}
22 changes: 22 additions & 0 deletions playground/rolldown-dev-mpa/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from 'vite'

export default defineConfig({
clearScreen: false,
environments: {
client: {
build: {
rollupOptions: {
input: {
index: './index.html',
about: './about/index.html',
},
},
},
},
},
experimental: {
rolldownDev: {
hmr: true,
},
},
})
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading