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

Conversation

underfin
Copy link
Member

@underfin underfin commented Apr 9, 2025

Current status

Rolldown vite already integrated rolldown at dev build, could using npx vite --fullBundleMode to preview it. It only used at client build, the ssr is not supported at now.

integrated HMR features

  • propagate to root
  • self accept
  • accept deps
  • import.hot.invalidate
  • (wip) import.hot.acceptExports
  • (pending) CSS hmr
  • (new) support load module exports by import.meta.hot.getExports(), react plugin ref

Plugins

Test status

  • define
  • hmr-root
  • (wip) hmr

Break changes

  • The xxx.html could be seen at original vite dev, but not added it to build.rollupOptions.input. In full bundle mode, you need to add the build.rollupOptions.input to make sure the HTML could be seen.rolldown vite test ref
  • The xxx.js could be seen at original vite dev, but it can't at full bundle mode.react plugin test ref
  • The html transformIndexHtml default order is post, it will inject some code to HTML, if it need to import module, it can't work at full bundle mode. The injected code need to bundled, you need to set the order to pre. react plugin ref

Break changes but could be improved

  • The implicit feature with soft invalidate, it make sure the transform hook is called once at original vite. In full bundle mode, it should be once, but not implement at now, we could improve it at future. rolldown vite test ref
  • The html transformIndexHtml is running at build, the config.server is invalid. react plugin ref

@underfin underfin marked this pull request as draft April 9, 2025 09:52
@underfin underfin force-pushed the rolldown-vite-full-bundle-mode branch from f46540b to 744fe8b Compare April 15, 2025 08:12
@underfin underfin force-pushed the rolldown-vite-full-bundle-mode branch from c580d0c to 191a670 Compare April 21, 2025 08:33
Copy link

pkg-pr-new bot commented Apr 21, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vitejs/rolldown-vite@107

commit: bfb953f

@underfin underfin changed the title wip: rolldown vite full bundle mode feat: rolldown vite full bundle mode Apr 21, 2025
'\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.

@underfin underfin marked this pull request as ready for review April 21, 2025 10:14
@underfin underfin marked this pull request as draft April 22, 2025 02:21
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.

'\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

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.

Comment on lines +222 to +225
if (!server.httpServer) {
throw new Error('HTTP server not available')
}
Copy link
Member

Choose a reason for hiding this comment

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

We should probably support middleware mode (it does not have server.httpServer) in the future.

@underfin underfin force-pushed the rolldown-vite-full-bundle-mode branch 2 times, most recently from 657dbc6 to e44af73 Compare April 29, 2025 08:56
@underfin underfin force-pushed the rolldown-vite-full-bundle-mode branch from 635f53f to 5d68ea9 Compare May 7, 2025 07:32
@gabrielcsapo

This comment was marked as off-topic.

@underfin

This comment was marked as off-topic.

@underfin underfin force-pushed the rolldown-vite-full-bundle-mode branch from 79e2b43 to 6593719 Compare May 14, 2025 06:42
@underfin underfin force-pushed the rolldown-vite-full-bundle-mode branch from 9265346 to bdb70a9 Compare May 19, 2025 08:41
@underfin underfin force-pushed the rolldown-vite-full-bundle-mode branch from 2fc1ba0 to bfb953f Compare May 26, 2025 10:06
Comment on lines -69 to +72
isBuild: config.command === 'build',
isBuild,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be instead? Does it actually need to set isBuild: false? If so, why?

isBuild: config.command === 'build',
optimizeDeps: false,

Copy link
Member Author

Choose a reason for hiding this comment

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

The full bundle mode also is build, here only add a condition with config.command === 'build' || experimental.fullBundleMode. The production mode maybe could be removed.
Here need to ensure consistency with build.

Comment on lines +690 to +692
treeshake: experimental.fullBundleMode
? false
: options.rollupOptions.treeshake,
Copy link
Member

Choose a reason for hiding this comment

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

Why does this have to be false?

Copy link
Member Author

Choose a reason for hiding this comment

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

The treeshake will remove unused code, but the unused code maybe using at hmr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants