Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
ced0ba3
feat: add experimental.fullBundleMode
sapphi-red May 27, 2025
753d545
feat: add `--fullBundleMode` flag for `vite dev`
sapphi-red May 27, 2025
46dce4a
feat: add `ResolvedConfig.isBundled`
sapphi-red May 27, 2025
00bc624
feat: disable minify by default in development
sapphi-red Jun 4, 2025
9360242
feat: disable json minify by default in development
sapphi-red Jun 4, 2025
546a8c4
Revert "feat: disable minify by default in development"
sapphi-red Jun 16, 2025
d17db91
Revert "feat: disable json minify by default in development"
sapphi-red Jun 16, 2025
122b93a
refactor: make `invalidateModule` function in DevEnvironment a method
sapphi-red Jun 13, 2025
d1a9df3
feat: disable minify by default in full bundle mode
sapphi-red Jun 16, 2025
2beac78
feat: disable buildImportAnalysisPlugin for full bundle mode
sapphi-red Jun 16, 2025
c81be70
wip: full bundle dev env
sapphi-red May 27, 2025
7bf6507
wip: revamp state handling
sapphi-red Jun 5, 2025
20f4332
wip: full bundle dev env
sapphi-red Jun 6, 2025
dad8e21
test: add test for basic scenarios
sapphi-red Jun 10, 2025
8d135de
wip: support assets
sapphi-red Jul 9, 2025
cc425e8
wip: update for new rolldown
sapphi-red Jul 11, 2025
df3b524
perf: skip warmup requests
sapphi-red Jul 15, 2025
35d4bed
perf: avoid buildStart hook call
sapphi-red Jul 15, 2025
a2761e4
wip: full bundle dev env
sapphi-red Jul 18, 2025
f12c4fd
wip: update for new rolldown
sapphi-red Jul 30, 2025
6ef3f2e
wip: simplify
sapphi-red Jul 31, 2025
613590e
wip: skip optimizerResolvePlugin
sapphi-red Jul 31, 2025
6b71514
wip: change flag to --full-bundle
sapphi-red Jul 31, 2025
1f004d5
wip: fix dynamic import vars plugin
sapphi-red Aug 1, 2025
2c998fd
wip: fix define/modulePreloadPolyfill plugin
sapphi-red Aug 4, 2025
3282eab
perf: skip worker renderChunk in dev
sapphi-red Aug 4, 2025
afa7457
wip: add debug time
sapphi-red Aug 4, 2025
b103bb1
perf: copy files lazily
sapphi-red Aug 4, 2025
af39c9f
wip: disable renderBuiltUrl in dev
sapphi-red Aug 5, 2025
4f8e8db
wip: pass path as-is to `hmrInvalidate`
sapphi-red Aug 12, 2025
d1deb02
wip: full bundle dev env
sapphi-red Aug 22, 2025
0971a0d
wip: full bundle dev env
sapphi-red Aug 27, 2025
421d2b8
wip: full bundle dev env
sapphi-red Aug 27, 2025
78eb19f
wip: full bundle dev env
sapphi-red Aug 27, 2025
db13109
wip: full bundle dev env
sapphi-red Aug 27, 2025
6031b05
wip: update
sapphi-red Sep 11, 2025
83bf1d1
wip: update
sapphi-red Sep 11, 2025
2b95331
wip: update
sapphi-red Sep 11, 2025
dd9336b
wip: use dev api
sapphi-red Sep 9, 2025
e57ba8d
wip: update
sapphi-red Sep 10, 2025
d98243e
wip: update
sapphi-red Sep 10, 2025
46d8663
wip: update
sapphi-red Sep 11, 2025
0482d22
wip: update
sapphi-red Sep 11, 2025
8ddfb2e
wip: update
sapphi-red Sep 16, 2025
1c0cccf
wip: update
sapphi-red Sep 16, 2025
1490297
wip: update
sapphi-red Sep 18, 2025
458346f
wip: update
sapphi-red Sep 18, 2025
b5f2d97
fix: rebuild
sapphi-red Sep 24, 2025
4a43f59
test: skip some
sapphi-red Sep 24, 2025
cf2cab8
wip: update
sapphi-red Sep 24, 2025
030efaf
wip: reject no-cors requests
sapphi-red Sep 24, 2025
a685ef1
wip: update
sapphi-red Sep 25, 2025
b9d3188
wip: initial client concept impl
sapphi-red Sep 25, 2025
91c9a85
wip: update
sapphi-red Sep 25, 2025
a4b92ec
wip: set etag
sapphi-red Sep 30, 2025
616b218
wip: update
sapphi-red Sep 30, 2025
960b13d
wip: update
sapphi-red Oct 6, 2025
97800e0
wip: update
sapphi-red Oct 6, 2025
c81e6d3
wip: update
sapphi-red Oct 15, 2025
53b304e
wip: update
sapphi-red Oct 15, 2025
1ce8ff9
wip: update
sapphi-red Oct 15, 2025
7703432
wip: update
sapphi-red Oct 16, 2025
402aaeb
wip: update
sapphi-red Oct 20, 2025
ea5ee75
wip: update
sapphi-red Oct 21, 2025
86be007
wip: update
sapphi-red Oct 21, 2025
68a2b3a
wip: update
sapphi-red Oct 21, 2025
942cb2b
wip: use hot API
sapphi-red Oct 21, 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
107 changes: 82 additions & 25 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 +38,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 +142,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 +616,37 @@ export function injectQuery(url: string, queryToInject: string): string {
}

export { ErrorOverlay }

// TODO: proper types
declare let DevRuntime: { new (socket: any): any } | undefined

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

applyUpdates(_boundaries: string[]): void {
// 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 @@ -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 @@ -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