Skip to content
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
3 changes: 2 additions & 1 deletion packages/vite/src/node/__tests_dts__/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type HooksMissingInConstants = Exclude<

export type cases = [
// Ensure environment plugin hooks are superset of rollup plugin hooks
ExpectTrue<ExpectExtends<RolldownPlugin, Plugin>>,
// (`hotUpdate` intentionally diverges — see `Plugin` in plugin.ts)
ExpectTrue<ExpectExtends<Omit<RolldownPlugin, 'hotUpdate'>, Plugin>>,

// Ensure all Rollup hooks have Vite's plugin context extension
ExpectTrue<Equal<HooksMissingExtension, never>>,
Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ declare module 'rolldown' {
* Environment Plugins are closer to regular rollup plugins. They can't define
* app level hooks (like config, configResolved, configureServer, etc).
*/
export interface Plugin<A = any> extends RolldownPlugin<A> {
// rolldown's dev-only `hotUpdate` takes plain module ids while Vite's takes
// `EnvironmentModuleNode`s; `bundledDevHmr.ts` bridges them.
export interface Plugin<A = any> extends Omit<RolldownPlugin<A>, 'hotUpdate'> {
/**
* Perform custom handling of HMR updates.
* The handler receives an options containing changed filename, timestamp, a
Expand Down
29 changes: 28 additions & 1 deletion packages/vite/src/node/server/bundledDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
createDebugger,
formatAndTruncateFileList,
} from '../utils'
import type { ViteDevServer } from '..'
import type { DevEnvironment } from './environment'
import { BundledDevHotUpdateAdapter, BundledModuleGraph } from './bundledDevHmr'
import { type NormalizedHotChannelClient, debugHmr, getShortName } from './hmr'
import { prepareError } from './middlewares/error'

Expand Down Expand Up @@ -78,12 +80,26 @@ export class BundledDev {

memoryFiles: MemoryFiles = new MemoryFiles()

readonly moduleGraph: BundledModuleGraph

private hotUpdateAdapter: BundledDevHotUpdateAdapter

constructor(private environment: DevEnvironment) {
if (environment.name !== 'client') {
throw new Error(
'currently full bundle mode is only available for client environment',
)
}
this.moduleGraph = new BundledModuleGraph(
environment.name,
environment.config.root,
(url: string) => environment.pluginContainer!.resolveId(url, undefined),
)
this.hotUpdateAdapter = new BundledDevHotUpdateAdapter(
environment,
this.moduleGraph,
this,
)
}

private get devEngine(): DevEngine {
Expand All @@ -95,8 +111,9 @@ export class BundledDev {

private pendingPayloadFilenames = new Set<string>()

async listen(): Promise<void> {
async listen(server: ViteDevServer): Promise<void> {
this._closed = false
this.hotUpdateAdapter.setServer(server)
debug?.('INITIAL: setup bundle options')
const rolldownOptions = await this.getRolldownOptions()
// NOTE: only single outputOptions is supported here
Expand Down Expand Up @@ -282,6 +299,11 @@ export class BundledDev {
return result
}

requestFullBuildReload(): void {
this.fullReloadPending = true
this.devEngine.triggerFullBuild()
}

/**
* Called by the serving middlewares when the response for a payload completed.
* Only delivered payloads are recorded on the server's per-client ship map, so
Expand Down Expand Up @@ -359,6 +381,11 @@ export class BundledDev {
transform.handler = wrappedHandler
}
}
// Run Vite's `hotUpdate` / `handleHotUpdate` plugin contracts on
// rolldown's dev-only `hotUpdate` hook — per-plugin wrappers, so plugin
// order is preserved by rolldown's driver.
this.hotUpdateAdapter.wrapPlugins(plugins)

rolldownOptions.plugins = plugins

// set filenames to make output paths predictable so that `renderChunk` hook does not need to be used
Expand Down
Loading