Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4ce4cc0
feat: add experimental.fullBundleMode
sapphi-red May 27, 2025
238fcb3
feat: add `--fullBundleMode` flag for `vite dev`
sapphi-red May 27, 2025
0f99ccb
feat: add `ResolvedConfig.isBundled`
sapphi-red May 27, 2025
f8f300d
feat: disable minify by default in development
sapphi-red Jun 4, 2025
9d903e1
feat: disable json minify by default in development
sapphi-red Jun 4, 2025
ae99dc5
Revert "feat: disable minify by default in development"
sapphi-red Jun 16, 2025
607d733
Revert "feat: disable json minify by default in development"
sapphi-red Jun 16, 2025
6159caf
refactor: make `invalidateModule` function in DevEnvironment a method
sapphi-red Jun 13, 2025
a62e965
feat: disable minify by default in full bundle mode
sapphi-red Jun 16, 2025
3de8fb0
feat: disable buildImportAnalysisPlugin for full bundle mode
sapphi-red Jun 16, 2025
af119fc
wip: full bundle dev env
sapphi-red May 27, 2025
b9e46d5
wip: revamp state handling
sapphi-red Jun 5, 2025
39bf0b0
wip: full bundle dev env
sapphi-red Jun 6, 2025
ef77855
test: add test for basic scenarios
sapphi-red Jun 10, 2025
625d3ca
wip: support assets
sapphi-red Jul 9, 2025
cebffef
wip: update for new rolldown
sapphi-red Jul 11, 2025
c6a85ea
perf: skip warmup requests
sapphi-red Jul 15, 2025
e15f09e
perf: avoid buildStart hook call
sapphi-red Jul 15, 2025
9a03f88
wip: full bundle dev env
sapphi-red Jul 18, 2025
528a1f5
wip: update for new rolldown
sapphi-red Jul 30, 2025
0b2147b
wip: simplify
sapphi-red Jul 31, 2025
e264a0b
wip: skip optimizerResolvePlugin
sapphi-red Jul 31, 2025
eab2ef0
wip: change flag to --full-bundle
sapphi-red Jul 31, 2025
afac716
wip: fix dynamic import vars plugin
sapphi-red Aug 1, 2025
9f0a928
wip: fix define/modulePreloadPolyfill plugin
sapphi-red Aug 4, 2025
ddd0f9e
perf: skip worker renderChunk in dev
sapphi-red Aug 4, 2025
c51ac1f
wip: add debug time
sapphi-red Aug 4, 2025
0d222cd
perf: copy files lazily
sapphi-red Aug 4, 2025
b69576b
wip: disable renderBuiltUrl in dev
sapphi-red Aug 5, 2025
bfff9af
wip: pass path as-is to `hmrInvalidate`
sapphi-red Aug 12, 2025
2ffe3d0
wip: full bundle dev env
sapphi-red Aug 22, 2025
0d29a6b
wip: full bundle dev env
sapphi-red Aug 27, 2025
69f19d1
wip: full bundle dev env
sapphi-red Aug 27, 2025
25c8f0a
wip: full bundle dev env
sapphi-red Aug 27, 2025
3178f10
wip: full bundle dev env
sapphi-red Aug 27, 2025
7028d4e
wip: update
sapphi-red Sep 11, 2025
3912990
wip: update
sapphi-red Sep 11, 2025
cb83aa9
wip: update
sapphi-red Sep 11, 2025
69aa061
wip: use dev api
sapphi-red Sep 9, 2025
9e5fe76
wip: update
sapphi-red Sep 10, 2025
ea17612
wip: update
sapphi-red Sep 10, 2025
bef42fb
wip: update
sapphi-red Sep 11, 2025
f14212b
wip: update
sapphi-red Sep 11, 2025
70fb459
wip: update
sapphi-red Sep 16, 2025
d05fd7b
wip: update
sapphi-red Sep 16, 2025
9fa7f6f
wip: update
sapphi-red Sep 18, 2025
0e8c2a6
wip: update
sapphi-red Sep 18, 2025
57c442d
fix: rebuild
sapphi-red Sep 24, 2025
080cf6d
test: skip some
sapphi-red Sep 24, 2025
2bd7803
wip: update
sapphi-red Sep 24, 2025
30f38d4
wip: reject no-cors requests
sapphi-red Sep 24, 2025
0452bc9
wip: update
sapphi-red Sep 25, 2025
9e0a90b
wip: initial client concept impl
sapphi-red Sep 25, 2025
fa00ddd
wip: update
sapphi-red Sep 25, 2025
b1293f4
wip: set etag
sapphi-red Sep 30, 2025
f5984f7
wip: update
sapphi-red Sep 30, 2025
a97b4dc
wip: update
sapphi-red Oct 6, 2025
8092ec7
wip: update
sapphi-red Oct 6, 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
113 changes: 88 additions & 25 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="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 +21,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 +39,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 +143,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 @@ -570,3 +594,42 @@ export function injectQuery(url: string, queryToInject: string): string {
}

export { ErrorOverlay }

if (isFullBundleMode && typeof DevRuntime !== 'undefined') {
class ViteDevRuntime extends DevRuntime {
override createModuleHotContext(moduleId: string) {
const ctx = createHotContext(moduleId)
// @ts-expect-error TODO: support CSS
ctx._internal = {
updateStyle,
removeStyle,
}
// @ts-expect-error TODO: support this function (used by plugin-react)
ctx.getExports = async () =>
// @ts-expect-error __rolldown_runtime__ / ctx.ownerPath
__rolldown_runtime__.loadExports(ctx.ownerPath)
return ctx
}

override applyUpdates(_boundaries: string[]): void {
// TODO: how should this be handled?
// noop, handled in the HMR client
}
}

// TODO: make this more performant
const wrappedSocket = {
readyState: WebSocket.OPEN,
send(data: string) {
const d = JSON.parse(data)
transport.send({
type: 'custom',
event: 'vite:module-loaded',
data: { modules: d.modules },
})
},
}
;(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 @@ -407,6 +407,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 @@ -427,7 +428,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 @@ -488,10 +489,11 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
pre: Plugin[]
post: Plugin[]
}> {
const isBuild = config.command === 'build'
return {
pre: [
completeSystemWrapPlugin(),
...(!config.isWorker ? [prepareOutDirPlugin()] : []),
...(isBuild && !config.isWorker ? [prepareOutDirPlugin()] : []),
perEnvironmentPlugin(
'vite:rollup-options-plugins',
async (environment) =>
Expand All @@ -504,11 +506,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
? [
manifestPlugin(config),
ssrManifestPlugin(),
Expand Down Expand Up @@ -549,10 +551,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 @@ -876,7 +878,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 @@ -1042,7 +1044,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