Skip to content

feat: rolldown vite full bundle mode #107

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 76 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
76 commits
Select commit Hold shift + click to select a range
0d4d6c0
feat: rolldown full bundle mode
underfin Apr 8, 2025
25f3e0e
feat: make memory files middleware work
underfin Apr 8, 2025
f183472
fix: make js define plugin works at dev build
underfin Apr 8, 2025
c57d182
fix: disable rolldown minify at devlopment build
underfin Apr 8, 2025
2bbb201
fix: make watcher + rolldown hmr build work
underfin Apr 9, 2025
cf9e3cc
chore: disable ws validate connnection
underfin Apr 9, 2025
6390882
chore: disable dev plugin relate logic
underfin Apr 10, 2025
804a636
chore: enable loadfallback plugin at dev build
underfin Apr 10, 2025
809c553
chore: disable depOptimizer
underfin Apr 10, 2025
2715861
fix: set correct header for memory files
underfin Apr 10, 2025
bba3e73
chore: make test work, avoid overrides vitest vite
underfin Apr 10, 2025
0a5a51a
chore: avoid watcher outdir
underfin Apr 10, 2025
8a6293d
chore: fix lint
underfin Apr 14, 2025
d47db7c
fix: some isBuild using production mode
underfin Apr 14, 2025
065e406
feat: using vite hmr runtime
underfin Apr 15, 2025
947ec1e
fix: using rolldown hmr info
underfin Apr 16, 2025
2cf5ff5
fix: define plugin should handle import.meta.hot
underfin Apr 16, 2025
4452731
chore: revert ws connection logic
underfin Apr 18, 2025
f3fe74d
chore: patch rolldown runtime update
underfin Apr 18, 2025
c90d37b
fix: disable chunksReporter at development build
underfin Apr 18, 2025
f9c4c9f
fix: aovid resolveConfig twice at dev build
underfin Apr 18, 2025
01ed745
feat: add experimental.fullBundleMode option
underfin Apr 21, 2025
2e990e6
chore: add comment code
underfin Apr 21, 2025
86e5869
chore: update pnpm.lock
underfin Apr 21, 2025
0294228
chore: fix createBuilder typing
underfin Apr 21, 2025
0768736
chore: fix cli fullBundleMode
underfin Apr 21, 2025
8a0f40c
fix: __FULL_BUNDLE_MODE__ replace
underfin Apr 21, 2025
7aba832
fix: merge experimental options
sapphi-red Apr 21, 2025
3d991d9
fix: aovid replace import.meta.hot at full bundle mode
underfin Apr 21, 2025
0d4f34c
fix: unit test
underfin Apr 21, 2025
9278245
fix: define at full bundle mode
underfin Apr 22, 2025
647fba4
Update packages/vite/src/client/hmrModuleRunner.ts
underfin Apr 22, 2025
3909c8b
Update packages/vite/src/client/hmrModuleRunner.ts
underfin Apr 22, 2025
9f4cdc5
chore: update clientInjection
underfin Apr 22, 2025
23d8d36
fix: skip cachedTransformMiddleware at full bundle mode
underfin Apr 22, 2025
cb6710f
fix: enable servePublicMiddleware at full bundle mode
underfin Apr 22, 2025
5e9a7ca
fix: make sure the server port and then start build
underfin Apr 22, 2025
cff15fb
refatcor: extract replaceClientConfigValues
underfin Apr 22, 2025
7966b11
fix: aoivd import @vite/env at custome rolldown runtime
underfin Apr 22, 2025
1aafd0d
fix: hmr root
underfin Apr 22, 2025
d3feb62
fix: close bundle at cli exit
underfin Apr 22, 2025
e75f4e9
fix: aovid replace import.met.hot to undefined
underfin Apr 23, 2025
9b34da0
feat: setup full bundle mode test
underfin Apr 23, 2025
60b406e
fix: aovid replace import.met.hot to undefined
underfin Apr 23, 2025
c509336
fix: enable createEsmInitializer createCjsInitializer
underfin Apr 24, 2025
b2493f2
chore: update hmr log
underfin Apr 24, 2025
10b6a47
chore: update hmr test
underfin Apr 24, 2025
532b4f0
fix: pass hmr self accept test
underfin Apr 24, 2025
c1d2a74
chore: disable dynamic import warning at dev build
underfin Apr 25, 2025
bbb1def
chore: remove watch changed file log
underfin Apr 25, 2025
662fbb7
chore: pass deps related tests
underfin Apr 25, 2025
064c268
fix: pass some hmr invalidate tests
underfin Apr 29, 2025
28ad636
fix: ignored hmr soft invalidate
underfin Apr 29, 2025
c404332
fix: invalidate in circular dep
underfin Apr 30, 2025
6d4a115
chore: disable not entry html hmr test and css hmr test
underfin Apr 30, 2025
4d51f1d
chore: skip rolldown hmr for outside module graph
underfin Apr 30, 2025
955a7ab
chore: fix lint
underfin May 7, 2025
930092e
fix: disable treeshake becasue the minify is disabled
underfin May 7, 2025
7976768
fix: htmlFallbackMiddleware should check fullBundleMode memoryFiles
underfin May 8, 2025
09e498e
fix: patch rolldown module runner changes
underfin May 9, 2025
bac444e
feat: add hmr hot getExports
underfin May 9, 2025
7ade2bc
chore: patch rolldown module runner changes
underfin May 12, 2025
eb361ca
chore: run hmr at first
underfin May 12, 2025
467b118
feat: debounce reBuild
underfin May 13, 2025
bd44ee2
chore: using await bundle.watchFiles
underfin May 13, 2025
950428b
chore: add hmr html files to rollupOptions.input
underfin May 13, 2025
9c7f704
fix: react plugin get module exports
underfin May 13, 2025
80f53db
feat: add build moduleGraph
underfin May 15, 2025
acd2c41
feat: make sourcemap work at full bundle mode dev
underfin May 16, 2025
f03bc47
chore: disable BuildModuleGraph
underfin May 19, 2025
bdb70a9
chore: rebase
underfin May 19, 2025
f7dc0b7
fix: aovid build oxc pluin enable jsx option
underfin May 20, 2025
9f56cb8
fix: eanble native nativeModulePreloadPolyfillPlugin
underfin May 21, 2025
01090e0
chore: fix fmt
underfin May 21, 2025
a28f815
fix: add cwd to hmr test
underfin May 22, 2025
bfb953f
chore: add test-full-bundle-mode in ci
underfin May 22, 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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ jobs:
- name: Test serve
run: pnpm run test-serve

- name: Test full bundle mode serve
run: pnpm run test-full-bundle-mode

- name: Test build
run: pnpm run test-build

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"format": "prettier --write --cache .",
"lint": "eslint --cache .",
"typecheck": "tsc -p scripts --noEmit && pnpm -r --parallel run typecheck",
"test": "pnpm test-unit && pnpm test-serve && pnpm test-build",
"test": "pnpm test-unit && pnpm test-serve && pnpm run test-full-bundle-mode && pnpm test-build",
"test-full-bundle-mode": "VITE_TEST_FULL_BUNDLE_MODE=1 vitest run -c vitest.config.e2e.ts",
"test-serve": "vitest run -c vitest.config.e2e.ts",
"test-build": "VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"test-unit": "vitest run",
Expand Down Expand Up @@ -98,6 +99,7 @@
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"vitest>vite": "npm:vite@^6.2.6",
"vite": "workspace:rolldown-vite@*"
},
"patchedDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/vite/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Object.assign(module.exports, require('./dist/node-cjs/publicUtils.cjs'))
const asyncFunctions = [
'build',
'createServer',
'createServerWithResolvedConfig',
'preview',
'transformWithEsbuild',
'transformWithOxc',
Expand Down
39 changes: 29 additions & 10 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../shared/moduleRunnerTransport'
import { createHMRHandler } from '../shared/hmrHandler'
import { ErrorOverlay, overlayId } from './overlay'
import './hmrModuleRunner'
import '@vite/env'

// injected by the hmr plugin when served
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 Down Expand Up @@ -140,20 +142,36 @@ const hmrClient = new HMRClient(
},
transport,
async function importUpdatedModule({
url,
acceptedPath,
timestamp,
explicitImportRequired,
isWithinCircularImport,
}) {
const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`)
const importPromise = import(
/* @vite-ignore */
base +
acceptedPathWithoutQuery.slice(1) +
`?${explicitImportRequired ? 'import&' : ''}t=${timestamp}${
query ? `&${query}` : ''
}`
)
function importModuleWithFullBundleMode() {
const importPromise = import(base + url)
return importPromise.then(() =>
// @ts-expect-error globalThis.__rolldown_runtime__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, I think it's good to have the types exposed from rolldown so that we can use it like:

declare var __rolldown_runtime__: RolldownHmrRuntime

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.

globalThis.__rolldown_runtime__.loadExports(acceptedPath),
)
}

function importModule() {
const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`)
const importPromise = import(
/* @vite-ignore */
base +
acceptedPathWithoutQuery.slice(1) +
`?${explicitImportRequired ? 'import&' : ''}t=${timestamp}${
query ? `&${query}` : ''
}`
)
return importPromise
}

const importPromise = __FULL_BUNDLE_MODE__
? importModuleWithFullBundleMode()
: importModule()
if (isWithinCircularImport) {
importPromise.catch(() => {
console.info(
Expand All @@ -165,6 +183,7 @@ const hmrClient = new HMRClient(
}
return await importPromise
},
__FULL_BUNDLE_MODE__,
)
transport.connect!(createHMRHandler(handleMessage))

Expand Down Expand Up @@ -436,7 +455,7 @@ export function removeStyle(id: string): void {
}

export function createHotContext(ownerPath: string): ViteHotContext {
return new HMRContext(hmrClient, ownerPath)
return new HMRContext(hmrClient, ownerPath, __FULL_BUNDLE_MODE__)
}

/**
Expand Down
63 changes: 63 additions & 0 deletions packages/vite/src/client/hmrModuleRunner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { createHotContext } from './client'

declare const __FULL_BUNDLE_MODE__: boolean

if (__FULL_BUNDLE_MODE__) {
class DevRuntime {
modules: Record<string, { exports: any }> = {}

static getInstance() {
// @ts-expect-error __rolldown_runtime__
let instance = globalThis.__rolldown_runtime__
if (!instance) {
instance = new DevRuntime()
// @ts-expect-error __rolldown_runtime__
globalThis.__rolldown_runtime__ = instance
}
return instance
}

createModuleHotContext(moduleId: string) {
return createHotContext(moduleId)
}

applyUpdates(_boundaries: string[]) {
//
}

registerModule(
id: string,
module: { exports: Record<string, () => unknown> },
) {
this.modules[id] = module
}

loadExports(id: string) {
const module = this.modules[id]
if (module) {
return module.exports
} else {
console.warn(`Module ${id} not found`)
return {}
}
}

// __esmMin
// @ts-expect-error need to add typing
createEsmInitializer = (fn, res) => () => (fn && (res = fn((fn = 0))), res)
// __commonJSMin
// @ts-expect-error need to add typing
createCjsInitializer = (cb, mod) => () => (
mod || cb((mod = { exports: {} }).exports, mod), mod.exports
)
// @ts-expect-error it is exits
__toESM = __toESM
// @ts-expect-error it is exits
__toCommonJS = __toCommonJS
// @ts-expect-error it is exits
__export = __export
}

// @ts-expect-error __rolldown_runtime__
globalThis.__rolldown_runtime__ ||= new DevRuntime()
}
3 changes: 2 additions & 1 deletion packages/vite/src/module-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class ModuleRunner {
resolvedHmrLogger,
this.transport,
({ acceptedPath }) => this.import(acceptedPath),
false,
)
if (!this.transport.connect) {
throw new Error(
Expand Down Expand Up @@ -391,7 +392,7 @@ export class ModuleRunner {
throw new Error(`[module runner] HMR client was closed.`)
}
this.debug?.('[module runner] creating hmr context for', mod.url)
hotContext ||= new HMRContext(this.hmrClient, mod.url)
hotContext ||= new HMRContext(this.hmrClient, mod.url, false)
return hotContext
},
set: (value) => {
Expand Down
5 changes: 1 addition & 4 deletions packages/vite/src/node/__tests__/plugins/import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ describe('transformCjsImport', () => {
),
).toBe(
'import __vite__cjsImport0_react from "./node_modules/.vite/deps/react.js"; ' +
'const react = ((m) => m?.__esModule ? m : {\n' +
'\t...typeof m === "object" && !Array.isArray(m) || typeof m === "function" ? m : {},\n' +
'\tdefault: m\n' +
'})(__vite__cjsImport0_react)',
'const react = ((m) => m?.__esModule ? m : { ...typeof m === "object" && !Array.isArray(m) || typeof m === "function" ? m : {}, default: m })(__vite__cjsImport0_react)',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is wired for it coudle be success at rolldown-vite branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably caused by the "vitest>vite" overrides. Vitest uses Vite to process the files and that changes the Function::toString result.

)
})

Expand Down
Loading
Loading