Skip to content

Commit 54e1393

Browse files
committed
feat: integrate rolldown hmr-poc
1 parent cac6eb8 commit 54e1393

31 files changed

+1148
-80
lines changed

packages/vite/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
"dependencies": {
8989
"esbuild": "^0.24.0",
9090
"postcss": "^8.4.48",
91-
"rolldown": "https://pkg.pr.new/rolldown@3d47bd0",
91+
"react-refresh": "^0.14.2",
92+
"rolldown": "0.13.2-snapshot-a292401-20241105072341",
9293
"rollup": "^4.23.0"
9394
},
9495
"devDependencies": {

packages/vite/src/node/build.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,7 @@ const relativeUrlMechanisms: Record<
13551355
`(typeof document === 'undefined' && typeof location === 'undefined' ? ${getFileUrlFromRelativePath(
13561356
relativePath,
13571357
)} : ${getRelativeUrlFromDocument(relativePath, true)})`,
1358+
app: () => 'todo',
13581359
}
13591360
/* end of copy */
13601361

packages/vite/src/node/config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ import { resolveSSROptions, ssrConfigDefaults } from './ssr'
9999
import { PartialEnvironment } from './baseEnvironment'
100100
import { createIdResolver } from './idResolver'
101101
import { type OxcOptions, convertEsbuildConfigToOxcConfig } from './plugins/oxc'
102+
import {
103+
type RolldownDevOptions,
104+
rolldownDevHandleConfig,
105+
} from './server/environments/rolldown'
102106

103107
const debug = createDebugger('vite:config', { depth: 10 })
104108
const promisifiedRealpath = promisify(fs.realpath)
@@ -518,6 +522,8 @@ export interface ExperimentalOptions {
518522
* @default true
519523
*/
520524
enableNativePlugin?: boolean
525+
526+
rolldownDev?: RolldownDevOptions
521527
}
522528

523529
export interface LegacyOptions {
@@ -1160,6 +1166,7 @@ export async function resolveConfig(
11601166
// run config hooks
11611167
const userPlugins = [...prePlugins, ...normalPlugins, ...postPlugins]
11621168
config = await runConfigHook(config, userPlugins, configEnv)
1169+
config = mergeConfig(config, rolldownDevHandleConfig(config, configEnv))
11631170

11641171
// Ensure default client and ssr environments
11651172
// If there are present, ensure order { client, ssr, ...custom }

packages/vite/src/node/plugins/asset.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ export async function fileToUrl(
275275
id: string,
276276
): Promise<string> {
277277
const { environment } = pluginContext
278-
if (environment.config.command === 'serve') {
278+
if (
279+
environment.config.command === 'serve' &&
280+
!environment.config.experimental.rolldownDev
281+
) {
279282
return fileToDevUrl(environment, id)
280283
} else {
281284
return fileToBuiltUrl(pluginContext, id)

packages/vite/src/node/plugins/html.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,13 @@ export function buildHtmlPlugin(config: ResolvedConfig): RolldownPlugin {
775775
tag: 'script',
776776
attrs: {
777777
...(isAsync ? { async: true } : {}),
778-
type: 'module',
778+
...(config.experimental.rolldownDev
779+
? {
780+
defer: true,
781+
}
782+
: {
783+
type: 'module',
784+
}),
779785
// crossorigin must be set not only for serving assets in a different origin
780786
// but also to make it possible to preload the script using `<link rel="preload">`.
781787
// `<script type="module">` used to fetch the script with credential mode `omit`,

packages/vite/src/node/plugins/index.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ export async function resolvePlugins(
4545
normalPlugins: Plugin[],
4646
postPlugins: Plugin[],
4747
): Promise<Plugin[]> {
48+
const rolldownDev = config.experimental.rolldownDev
4849
const isBuild = config.command === 'build'
4950
const isWorker = config.isWorker
50-
const buildPlugins = isBuild
51-
? await (await import('../build')).resolveBuildPlugins(config)
52-
: { pre: [], post: [] }
51+
const buildPlugins =
52+
isBuild || rolldownDev
53+
? await (await import('../build')).resolveBuildPlugins(config)
54+
: { pre: [], post: [] }
5355
const { modulePreload } = config.build
5456
const depOptimizationEnabled =
5557
!isBuild &&
@@ -60,7 +62,7 @@ export async function resolvePlugins(
6062

6163
return [
6264
depOptimizationEnabled ? optimizedDepsPlugin() : null,
63-
isBuild ? metadataPlugin() : null,
65+
rolldownDev || isBuild ? metadataPlugin() : null,
6466
!isWorker ? watchPackageDataPlugin(config.packageCache) : null,
6567
!isBuild ? preAliasPlugin(config) : null,
6668
enableNativePlugin
@@ -118,9 +120,18 @@ export async function resolvePlugins(
118120
htmlInlineProxyPlugin(config),
119121
cssPlugin(config),
120122
config.oxc !== false
121-
? enableNativePlugin
122-
? nativeTransformPlugin()
123-
: oxcPlugin(config)
123+
? rolldownDev
124+
? createBuiltinPluginWithEnvironmentSupport(
125+
'native:transform',
126+
(environment) =>
127+
nativeTransformPlugin({
128+
reactRefresh:
129+
environment.name === 'client' && rolldownDev?.reactRefresh,
130+
}),
131+
)
132+
: enableNativePlugin
133+
? nativeTransformPlugin()
134+
: oxcPlugin(config)
124135
: null,
125136
enableNativePlugin
126137
? nativeJsonPlugin({
@@ -141,7 +152,7 @@ export async function resolvePlugins(
141152
enableNativePlugin ? nativeWasmFallbackPlugin() : wasmFallbackPlugin(),
142153
definePlugin(config),
143154
cssPostPlugin(config),
144-
isBuild && buildHtmlPlugin(config),
155+
(rolldownDev || isBuild) && buildHtmlPlugin(config),
145156
workerImportMetaUrlPlugin(config),
146157
assetImportMetaUrlPlugin(config),
147158
...buildPlugins.pre,

0 commit comments

Comments
 (0)