Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
3709635
feat: add experimental.fullBundleMode
sapphi-red May 27, 2025
6c30381
feat: add `--fullBundleMode` flag for `vite dev`
sapphi-red May 27, 2025
2da7fe2
feat: add `ResolvedConfig.isBundled`
sapphi-red May 27, 2025
1654f48
feat: disable minify by default in development
sapphi-red Jun 4, 2025
0bf0732
feat: disable json minify by default in development
sapphi-red Jun 4, 2025
03d932a
Revert "feat: disable minify by default in development"
sapphi-red Jun 16, 2025
94f452e
Revert "feat: disable json minify by default in development"
sapphi-red Jun 16, 2025
3607ea6
refactor: make `invalidateModule` function in DevEnvironment a method
sapphi-red Jun 13, 2025
b192c81
feat: disable minify by default in full bundle mode
sapphi-red Jun 16, 2025
9f48268
feat: disable buildImportAnalysisPlugin for full bundle mode
sapphi-red Jun 16, 2025
a2697e9
wip: full bundle dev env
sapphi-red May 27, 2025
781880d
wip: revamp state handling
sapphi-red Jun 5, 2025
6aa1b6c
wip: full bundle dev env
sapphi-red Jun 6, 2025
3bd0e07
test: add test for basic scenarios
sapphi-red Jun 10, 2025
27e8ffa
wip: support assets
sapphi-red Jul 9, 2025
cc31878
wip: update for new rolldown
sapphi-red Jul 11, 2025
512d5f9
perf: skip warmup requests
sapphi-red Jul 15, 2025
9d34c4c
perf: avoid buildStart hook call
sapphi-red Jul 15, 2025
1b9eead
wip: full bundle dev env
sapphi-red Jul 18, 2025
b9ebca2
wip: update for new rolldown
sapphi-red Jul 30, 2025
e0c4467
wip: simplify
sapphi-red Jul 31, 2025
93fda49
wip: skip optimizerResolvePlugin
sapphi-red Jul 31, 2025
615fd12
wip: change flag to --full-bundle
sapphi-red Jul 31, 2025
25aee69
wip: fix dynamic import vars plugin
sapphi-red Aug 1, 2025
1c214c6
wip: fix define/modulePreloadPolyfill plugin
sapphi-red Aug 4, 2025
268ad11
perf: skip worker renderChunk in dev
sapphi-red Aug 4, 2025
bf88e60
wip: add debug time
sapphi-red Aug 4, 2025
63fd1ef
perf: copy files lazily
sapphi-red Aug 4, 2025
82e01b2
wip: disable renderBuiltUrl in dev
sapphi-red Aug 5, 2025
d926fe1
wip: pass path as-is to `hmrInvalidate`
sapphi-red Aug 12, 2025
1e57ed0
wip: full bundle dev env
sapphi-red Aug 22, 2025
d88855f
wip: full bundle dev env
sapphi-red Aug 27, 2025
e8d0a37
wip: full bundle dev env
sapphi-red Aug 27, 2025
ee3f8c1
wip: full bundle dev env
sapphi-red Aug 27, 2025
47a867b
wip: full bundle dev env
sapphi-red Aug 27, 2025
6af731b
wip: update
sapphi-red Sep 11, 2025
b318972
wip: update
sapphi-red Sep 11, 2025
6a876f7
wip: update
sapphi-red Sep 11, 2025
fc8fe72
wip: use dev api
sapphi-red Sep 9, 2025
88a16b5
wip: update
sapphi-red Sep 10, 2025
3692853
wip: update
sapphi-red Sep 10, 2025
db02fb0
wip: update
sapphi-red Sep 11, 2025
ff2f28c
wip: update
sapphi-red Sep 11, 2025
cf6e882
wip: update
sapphi-red Sep 16, 2025
4367cd0
wip: update
sapphi-red Sep 16, 2025
f0c1270
wip: update
sapphi-red Sep 18, 2025
a279edc
wip: update
sapphi-red Sep 18, 2025
a9ac2e6
fix: rebuild
sapphi-red Sep 24, 2025
fa6c0c7
test: skip some
sapphi-red Sep 24, 2025
5da25e0
wip: update
sapphi-red Sep 24, 2025
d1b1e0b
wip: reject no-cors requests
sapphi-red Sep 24, 2025
9a249f9
wip: update
sapphi-red Sep 25, 2025
f794fe3
wip: initial client concept impl
sapphi-red Sep 25, 2025
0d91251
wip: update
sapphi-red Sep 25, 2025
7b2293e
wip: set etag
sapphi-red Sep 30, 2025
19bf2c9
wip: update
sapphi-red Sep 30, 2025
ca7cc9e
wip: update
sapphi-red Oct 6, 2025
8466450
wip: update
sapphi-red Oct 6, 2025
c465c4b
wip: update
sapphi-red Oct 15, 2025
1676530
wip: update
sapphi-red Oct 15, 2025
1e11405
wip: update
sapphi-red Oct 15, 2025
d1bc1be
wip: update
sapphi-red Oct 16, 2025
34f1f2b
wip: update
sapphi-red Oct 20, 2025
41b5a44
wip: update
sapphi-red Oct 21, 2025
fd40aff
wip: update
sapphi-red Oct 21, 2025
651c617
wip: update
sapphi-red Oct 21, 2025
1417ec4
wip: use hot API
sapphi-red Oct 21, 2025
8df4a51
wip: fix hmr code
sapphi-red Nov 17, 2025
8a1c20e
wip: fix hmr code
sapphi-red Nov 17, 2025
36d9227
wip: disable inline const in dev
sapphi-red Nov 19, 2025
764824d
wip: fix disconnect
sapphi-red Nov 19, 2025
0c5af1a
wip: update
sapphi-red Dec 4, 2025
f1ab2bc
wip: update
sapphi-red Dec 5, 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 @@ -420,6 +420,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 @@ -440,7 +441,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 @@ -501,9 +502,10 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
pre: Plugin[]
post: Plugin[]
}> {
const isBuild = config.command === 'build'
return {
pre: [
...(!config.isWorker ? [prepareOutDirPlugin()] : []),
...(isBuild && !config.isWorker ? [prepareOutDirPlugin()] : []),
perEnvironmentPlugin(
'vite:rollup-options-plugins',
async (environment) =>
Expand All @@ -516,11 +518,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 @@ -562,10 +564,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 @@ -883,7 +885,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 @@ -1049,7 +1051,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