Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
f4d438d
feat: add experimental.fullBundleMode
sapphi-red May 27, 2025
2d3fe61
feat: add `--fullBundleMode` flag for `vite dev`
sapphi-red May 27, 2025
563f5d6
feat: add `ResolvedConfig.isBundled`
sapphi-red May 27, 2025
1b479eb
feat: disable minify by default in development
sapphi-red Jun 4, 2025
eff0237
feat: disable json minify by default in development
sapphi-red Jun 4, 2025
1a94f3f
Revert "feat: disable minify by default in development"
sapphi-red Jun 16, 2025
a3c06ad
Revert "feat: disable json minify by default in development"
sapphi-red Jun 16, 2025
e4c8e65
refactor: make `invalidateModule` function in DevEnvironment a method
sapphi-red Jun 13, 2025
84734e3
feat: disable minify by default in full bundle mode
sapphi-red Jun 16, 2025
22b318a
feat: disable buildImportAnalysisPlugin for full bundle mode
sapphi-red Jun 16, 2025
2b817e3
wip: full bundle dev env
sapphi-red May 27, 2025
943b339
wip: revamp state handling
sapphi-red Jun 5, 2025
d315e9c
wip: full bundle dev env
sapphi-red Jun 6, 2025
87a1f17
test: add test for basic scenarios
sapphi-red Jun 10, 2025
f4dfd85
wip: support assets
sapphi-red Jul 9, 2025
16e75b9
wip: update for new rolldown
sapphi-red Jul 11, 2025
d3efbed
perf: skip warmup requests
sapphi-red Jul 15, 2025
87f25f2
perf: avoid buildStart hook call
sapphi-red Jul 15, 2025
51689aa
wip: full bundle dev env
sapphi-red Jul 18, 2025
4f8d4f3
wip: update for new rolldown
sapphi-red Jul 30, 2025
06dfd9d
wip: simplify
sapphi-red Jul 31, 2025
fbfdab9
wip: skip optimizerResolvePlugin
sapphi-red Jul 31, 2025
805786a
wip: change flag to --full-bundle
sapphi-red Jul 31, 2025
e1c7da8
wip: fix dynamic import vars plugin
sapphi-red Aug 1, 2025
10a8c13
wip: fix define/modulePreloadPolyfill plugin
sapphi-red Aug 4, 2025
bf28f02
perf: skip worker renderChunk in dev
sapphi-red Aug 4, 2025
a10b544
wip: add debug time
sapphi-red Aug 4, 2025
2b5dfcb
perf: copy files lazily
sapphi-red Aug 4, 2025
0db5728
wip: disable renderBuiltUrl in dev
sapphi-red Aug 5, 2025
0052ee5
wip: pass path as-is to `hmrInvalidate`
sapphi-red Aug 12, 2025
d521a95
wip: full bundle dev env
sapphi-red Aug 22, 2025
6dd1f26
wip: full bundle dev env
sapphi-red Aug 27, 2025
ed84e39
wip: full bundle dev env
sapphi-red Aug 27, 2025
d3ddce6
wip: full bundle dev env
sapphi-red Aug 27, 2025
1e29004
wip: full bundle dev env
sapphi-red Aug 27, 2025
987c321
wip: update
sapphi-red Sep 11, 2025
ea715dc
wip: update
sapphi-red Sep 11, 2025
06f6d4f
wip: update
sapphi-red Sep 11, 2025
ff33bd2
wip: use dev api
sapphi-red Sep 9, 2025
2adb54e
wip: update
sapphi-red Sep 10, 2025
3c58c0e
wip: update
sapphi-red Sep 10, 2025
67d4d4d
wip: update
sapphi-red Sep 11, 2025
143fa94
wip: update
sapphi-red Sep 11, 2025
4b14df5
wip: update
sapphi-red Sep 16, 2025
2c40539
wip: update
sapphi-red Sep 16, 2025
c1ec4a5
wip: update
sapphi-red Sep 18, 2025
8ae8a87
wip: update
sapphi-red Sep 18, 2025
30dff1c
fix: rebuild
sapphi-red Sep 24, 2025
3c7a48d
test: skip some
sapphi-red Sep 24, 2025
bf11442
wip: update
sapphi-red Sep 24, 2025
b90a21d
wip: reject no-cors requests
sapphi-red Sep 24, 2025
2be13c9
wip: update
sapphi-red Sep 25, 2025
4c7ac57
wip: initial client concept impl
sapphi-red Sep 25, 2025
37019e5
wip: update
sapphi-red Sep 25, 2025
0d4aa39
wip: set etag
sapphi-red Sep 30, 2025
664486c
wip: update
sapphi-red Sep 30, 2025
37a0b6f
wip: update
sapphi-red Oct 6, 2025
1f7a42d
wip: update
sapphi-red Oct 6, 2025
932dd35
wip: update
sapphi-red Oct 15, 2025
043ffa6
wip: update
sapphi-red Oct 15, 2025
f8e30be
wip: update
sapphi-red Oct 15, 2025
bf1efaa
wip: update
sapphi-red Oct 16, 2025
366a30a
wip: update
sapphi-red Oct 20, 2025
978c3f1
wip: update
sapphi-red Oct 21, 2025
60a5469
wip: update
sapphi-red Oct 21, 2025
96e60c9
wip: update
sapphi-red Oct 21, 2025
89085c1
wip: use hot API
sapphi-red Oct 21, 2025
1586790
wip: fix hmr code
sapphi-red Nov 17, 2025
bc9f935
wip: fix hmr code
sapphi-red Nov 17, 2025
a5898a6
wip: disable inline const in dev
sapphi-red Nov 19, 2025
593b1e4
wip: fix disconnect
sapphi-red Nov 19, 2025
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
115 changes: 90 additions & 25 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type {
DevRuntime as DevRuntimeType,
Messenger,
} from 'rolldown/experimental/runtime-types'
import type { ErrorPayload, HotPayload } from '#types/hmrPayload'
import type { ViteHotContext } from '#types/hot'
import { HMRClient, HMRContext } from '../shared/hmr'
Expand All @@ -20,6 +24,7 @@ declare const __HMR_BASE__: string
declare const __HMR_TIMEOUT__: number
declare const __HMR_ENABLE_OVERLAY__: boolean
declare const __WS_TOKEN__: string
declare const __FULL_BUNDLE_MODE__: boolean

console.debug('[vite] connecting...')

Expand All @@ -37,6 +42,7 @@ const directSocketHost = __HMR_DIRECT_TARGET__
const base = __BASE__ || '/'
const hmrTimeout = __HMR_TIMEOUT__
const wsToken = __WS_TOKEN__
const isFullBundleMode = __FULL_BUNDLE_MODE__

const transport = normalizeModuleRunnerTransport(
(() => {
Expand Down Expand Up @@ -140,32 +146,53 @@ const hmrClient = new HMRClient(
debug: (...msg) => console.debug('[vite]', ...msg),
},
transport,
async function importUpdatedModule({
acceptedPath,
timestamp,
explicitImportRequired,
isWithinCircularImport,
}) {
const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`)
const importPromise = import(
/* @vite-ignore */
base +
acceptedPathWithoutQuery.slice(1) +
`?${explicitImportRequired ? 'import&' : ''}t=${timestamp}${
query ? `&${query}` : ''
}`
)
if (isWithinCircularImport) {
importPromise.catch(() => {
console.info(
`[hmr] ${acceptedPath} failed to apply HMR as it's within a circular import. Reloading page to reset the execution order. ` +
`To debug and break the circular import, you can run \`vite --debug hmr\` to log the circular dependency path if a file change triggered it.`,
isFullBundleMode
? async function importUpdatedModule({
url,
acceptedPath,
isWithinCircularImport,
}) {
const importPromise = import(base + url!).then(() =>
// @ts-expect-error globalThis.__rolldown_runtime__
globalThis.__rolldown_runtime__.loadExports(acceptedPath),
)
pageReload()
})
}
return await importPromise
},
if (isWithinCircularImport) {
importPromise.catch(() => {
console.info(
`[hmr] ${acceptedPath} failed to apply HMR as it's within a circular import. Reloading page to reset the execution order. ` +
`To debug and break the circular import, you can run \`vite --debug hmr\` to log the circular dependency path if a file change triggered it.`,
)
pageReload()
})
}
return await importPromise
}
: async function importUpdatedModule({
acceptedPath,
timestamp,
explicitImportRequired,
isWithinCircularImport,
}) {
const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`)
const importPromise = import(
/* @vite-ignore */
base +
acceptedPathWithoutQuery.slice(1) +
`?${explicitImportRequired ? 'import&' : ''}t=${timestamp}${
query ? `&${query}` : ''
}`
)
if (isWithinCircularImport) {
importPromise.catch(() => {
console.info(
`[hmr] ${acceptedPath} failed to apply HMR as it's within a circular import. Reloading page to reset the execution order. ` +
`To debug and break the circular import, you can run \`vite --debug hmr\` to log the circular dependency path if a file change triggered it.`,
)
pageReload()
})
}
return await importPromise
},
)
transport.connect!(createHMRHandler(handleMessage))

Expand Down Expand Up @@ -593,3 +620,41 @@ export function injectQuery(url: string, queryToInject: string): string {
}

export { ErrorOverlay }

declare const DevRuntime: typeof DevRuntimeType

if (isFullBundleMode && typeof DevRuntime !== 'undefined') {
class ViteDevRuntime extends DevRuntime {
override createModuleHotContext(moduleId: string) {
const ctx = createHotContext(moduleId)
// @ts-expect-error TODO: support CSS properly
ctx._internal = { updateStyle, removeStyle }
return ctx
}

override applyUpdates(_boundaries: [string, string][]): void {
// noop, handled in the HMR client
}
}

const wrappedSocket: Messenger = {
send(message) {
switch (message.type) {
case 'hmr:module-registered': {
transport.send({
type: 'custom',
event: 'vite:module-loaded',
// clone array as the runtime reuses the array instance
data: { modules: message.modules.slice() },
})
break
}
default:
throw new Error(`Unknown message type: ${JSON.stringify(message)}`)
}
},
}
;(globalThis as any).__rolldown_runtime__ ??= new ViteDevRuntime(
wrappedSocket,
)
}
20 changes: 11 additions & 9 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ export function resolveBuildEnvironmentOptions(
raw: BuildEnvironmentOptions,
logger: Logger,
consumer: 'client' | 'server' | undefined,
isFullBundledDev: boolean,
): ResolvedBuildEnvironmentOptions {
const deprecatedPolyfillModulePreload = raw.polyfillModulePreload
const { polyfillModulePreload, ...rest } = raw
Expand All @@ -439,7 +440,7 @@ export function resolveBuildEnvironmentOptions(
{
..._buildEnvironmentOptionsDefaults,
cssCodeSplit: !raw.lib,
minify: consumer === 'server' ? false : 'oxc',
minify: consumer === 'server' || isFullBundledDev ? false : 'oxc',
rollupOptions: {},
rolldownOptions: undefined,
ssr: consumer === 'server',
Expand Down Expand Up @@ -500,11 +501,12 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
pre: Plugin[]
post: Plugin[]
}> {
const isBuild = config.command === 'build'
return {
pre: [
completeAmdWrapPlugin(),
completeSystemWrapPlugin(),
...(!config.isWorker ? [prepareOutDirPlugin()] : []),
...(isBuild && !config.isWorker ? [prepareOutDirPlugin()] : []),
perEnvironmentPlugin(
'vite:rollup-options-plugins',
async (environment) =>
Expand All @@ -517,11 +519,11 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
...(config.isWorker ? [webWorkerPostPlugin(config)] : []),
],
post: [
...buildImportAnalysisPlugin(config),
...(isBuild ? buildImportAnalysisPlugin(config) : []),
...(config.nativePluginEnabledLevel >= 1 ? [] : [buildOxcPlugin()]),
...(config.build.minify === 'esbuild' ? [buildEsbuildPlugin()] : []),
terserPlugin(config),
...(!config.isWorker
...(isBuild ? [terserPlugin(config)] : []),
...(isBuild && !config.isWorker
? [
licensePlugin(),
manifestPlugin(config),
Expand Down Expand Up @@ -563,10 +565,10 @@ function resolveConfigToBuild(
)
}

function resolveRolldownOptions(
export function resolveRolldownOptions(
environment: Environment,
chunkMetadataMap: ChunkMetadataMap,
) {
): RolldownOptions {
const { root, packageCache, build: options } = environment.config
const libOptions = options.lib
const { logger } = environment
Expand Down Expand Up @@ -884,7 +886,7 @@ async function buildEnvironment(
}
}

function enhanceRollupError(e: RollupError) {
export function enhanceRollupError(e: RollupError): void {
const stackOnly = extractStack(e)

let msg = colors.red((e.plugin ? `[${e.plugin}] ` : '') + e.message)
Expand Down Expand Up @@ -1050,7 +1052,7 @@ const dynamicImportWarningIgnoreList = [
`statically analyzed`,
]

function clearLine() {
export function clearLine(): void {
const tty = process.stdout.isTTY && !process.env.CI
if (tty) {
process.stdout.clearLine(0)
Expand Down
Loading
Loading