Skip to content

feat: full bundle dev env #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 30 commits into
base: rolldown-vite
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
91982c7
feat: add experimental.fullBundleMode
sapphi-red May 27, 2025
3d0755f
feat: add `--fullBundleMode` flag for `vite dev`
sapphi-red May 27, 2025
71582a2
feat: add `ResolvedConfig.isBundled`
sapphi-red May 27, 2025
9b124cc
feat: disable minify by default in development
sapphi-red Jun 4, 2025
6790883
feat: disable json minify by default in development
sapphi-red Jun 4, 2025
090a5ca
Revert "feat: disable minify by default in development"
sapphi-red Jun 16, 2025
e7a70b8
Revert "feat: disable json minify by default in development"
sapphi-red Jun 16, 2025
b6fb374
refactor: make `invalidateModule` function in DevEnvironment a method
sapphi-red Jun 13, 2025
1ec5aa8
feat: disable minify by default in full bundle mode
sapphi-red Jun 16, 2025
2115819
feat: disable buildImportAnalysisPlugin for full bundle mode
sapphi-red Jun 16, 2025
e9758ad
wip: full bundle dev env
sapphi-red May 27, 2025
586a5e4
wip: revamp state handling
sapphi-red Jun 5, 2025
e6d352c
wip: full bundle dev env
sapphi-red Jun 6, 2025
5025956
test: add test for basic scenarios
sapphi-red Jun 10, 2025
f78da07
wip: support assets
sapphi-red Jul 9, 2025
9f877cf
wip: update for new rolldown
sapphi-red Jul 11, 2025
d8f5537
perf: skip warmup requests
sapphi-red Jul 15, 2025
48759ec
perf: avoid buildStart hook call
sapphi-red Jul 15, 2025
3100260
wip: full bundle dev env
sapphi-red Jul 18, 2025
86900b7
wip: update for new rolldown
sapphi-red Jul 30, 2025
bdb9450
wip: simplify
sapphi-red Jul 31, 2025
18eb8ab
wip: skip optimizerResolvePlugin
sapphi-red Jul 31, 2025
5e7975c
wip: change flag to --full-bundle
sapphi-red Jul 31, 2025
843abde
wip: fix dynamic import vars plugin
sapphi-red Aug 1, 2025
7b40cb6
wip: fix define/modulePreloadPolyfill plugin
sapphi-red Aug 4, 2025
be2ae2a
perf: skip worker renderChunk in dev
sapphi-red Aug 4, 2025
18b9b55
wip: add debug time
sapphi-red Aug 4, 2025
8419c88
perf: copy files lazily
sapphi-red Aug 4, 2025
d417fe5
wip: disable renderBuiltUrl in dev
sapphi-red Aug 5, 2025
84f6df3
wip: pass path as-is to `hmrInvalidate`
sapphi-red Aug 12, 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
99 changes: 74 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 @@ -575,3 +599,28 @@ export function injectQuery(url: string, queryToInject: string): string {
}

export { ErrorOverlay }

if (isFullBundleMode) {
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
}
}

;(globalThis as any).__rolldown_runtime__ ??= new ViteDevRuntime()
}
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,7 +506,7 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
...(config.isWorker ? [webWorkerPostPlugin(config)] : []),
],
post: [
...buildImportAnalysisPlugin(config),
...(isBuild ? buildImportAnalysisPlugin(config) : []),
...(config.experimental.enableNativePlugin !== true
? [
buildOxcPlugin(),
Expand All @@ -513,8 +515,8 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
: []),
]
: []),
terserPlugin(config),
...(!config.isWorker
...(isBuild ? [terserPlugin(config)] : []),
...(isBuild && !config.isWorker
? [
manifestPlugin(config),
ssrManifestPlugin(),
Expand Down Expand Up @@ -555,10 +557,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 @@ -864,7 +866,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 @@ -1030,7 +1032,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