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 35 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
35 commits
Select commit Hold shift + click to select a range
a71d5c8
feat: add experimental.fullBundleMode
sapphi-red May 27, 2025
c44e95b
feat: add `--fullBundleMode` flag for `vite dev`
sapphi-red May 27, 2025
8308b98
feat: add `ResolvedConfig.isBundled`
sapphi-red May 27, 2025
84cfb35
feat: disable minify by default in development
sapphi-red Jun 4, 2025
80547ba
feat: disable json minify by default in development
sapphi-red Jun 4, 2025
da7bf68
Revert "feat: disable minify by default in development"
sapphi-red Jun 16, 2025
3013f24
Revert "feat: disable json minify by default in development"
sapphi-red Jun 16, 2025
ba96ec6
refactor: make `invalidateModule` function in DevEnvironment a method
sapphi-red Jun 13, 2025
4897e08
feat: disable minify by default in full bundle mode
sapphi-red Jun 16, 2025
e3111fe
feat: disable buildImportAnalysisPlugin for full bundle mode
sapphi-red Jun 16, 2025
85ab705
wip: full bundle dev env
sapphi-red May 27, 2025
06d4c15
wip: revamp state handling
sapphi-red Jun 5, 2025
95fbccb
wip: full bundle dev env
sapphi-red Jun 6, 2025
7393265
test: add test for basic scenarios
sapphi-red Jun 10, 2025
fe1db45
wip: support assets
sapphi-red Jul 9, 2025
a88c1bc
wip: update for new rolldown
sapphi-red Jul 11, 2025
4f63f5e
perf: skip warmup requests
sapphi-red Jul 15, 2025
8f07c70
perf: avoid buildStart hook call
sapphi-red Jul 15, 2025
ec219b8
wip: full bundle dev env
sapphi-red Jul 18, 2025
5debc64
wip: update for new rolldown
sapphi-red Jul 30, 2025
3b60349
wip: simplify
sapphi-red Jul 31, 2025
fb8aa43
wip: skip optimizerResolvePlugin
sapphi-red Jul 31, 2025
dce4555
wip: change flag to --full-bundle
sapphi-red Jul 31, 2025
9f6eccf
wip: fix dynamic import vars plugin
sapphi-red Aug 1, 2025
87a799d
wip: fix define/modulePreloadPolyfill plugin
sapphi-red Aug 4, 2025
5e881ae
perf: skip worker renderChunk in dev
sapphi-red Aug 4, 2025
850ec9a
wip: add debug time
sapphi-red Aug 4, 2025
bfa60c4
perf: copy files lazily
sapphi-red Aug 4, 2025
75a607b
wip: disable renderBuiltUrl in dev
sapphi-red Aug 5, 2025
7ed9c4d
wip: pass path as-is to `hmrInvalidate`
sapphi-red Aug 12, 2025
7e9e6c8
wip: full bundle dev env
sapphi-red Aug 22, 2025
7e091e0
wip: full bundle dev env
sapphi-red Aug 27, 2025
122223e
wip: full bundle dev env
sapphi-red Aug 27, 2025
7319874
wip: full bundle dev env
sapphi-red Aug 27, 2025
d098bfc
wip: full bundle dev env
sapphi-red Aug 27, 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 && 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
}
}

;(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.nativePluginEnabledLevel >= 1
? []
: [
Expand All @@ -513,8 +515,8 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
? [buildEsbuildPlugin()]
: []),
]),
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 @@ -867,7 +869,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 @@ -1033,7 +1035,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