Skip to content

Commit

Permalink
feat: integrate rolldown hmr-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 15, 2024
1 parent 65d9acc commit 679576c
Show file tree
Hide file tree
Showing 31 changed files with 1,148 additions and 80 deletions.
3 changes: 2 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"dependencies": {
"esbuild": "^0.24.0",
"postcss": "^8.4.48",
"rolldown": "https://pkg.pr.new/rolldown@3d47bd0",
"react-refresh": "^0.14.2",
"rolldown": "0.13.2-snapshot-a292401-20241105072341",
"rollup": "^4.23.0"
},
"optionalDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ const relativeUrlMechanisms: Record<
`(typeof document === 'undefined' && typeof location === 'undefined' ? ${getFileUrlFromRelativePath(
relativePath,
)} : ${getRelativeUrlFromDocument(relativePath, true)})`,
app: () => 'todo',
}
/* end of copy */

Expand Down
7 changes: 7 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ import { resolveSSROptions, ssrConfigDefaults } from './ssr'
import { PartialEnvironment } from './baseEnvironment'
import { createIdResolver } from './idResolver'
import { type OxcOptions, convertEsbuildConfigToOxcConfig } from './plugins/oxc'
import {
type RolldownDevOptions,
rolldownDevHandleConfig,
} from './server/environments/rolldown'

const debug = createDebugger('vite:config', { depth: 10 })
const promisifiedRealpath = promisify(fs.realpath)
Expand Down Expand Up @@ -518,6 +522,8 @@ export interface ExperimentalOptions {
* @default true
*/
enableNativePlugin?: boolean

rolldownDev?: RolldownDevOptions
}

export interface LegacyOptions {
Expand Down Expand Up @@ -1160,6 +1166,7 @@ export async function resolveConfig(
// run config hooks
const userPlugins = [...prePlugins, ...normalPlugins, ...postPlugins]
config = await runConfigHook(config, userPlugins, configEnv)
config = mergeConfig(config, rolldownDevHandleConfig(config, configEnv))

// Ensure default client and ssr environments
// If there are present, ensure order { client, ssr, ...custom }
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ export async function fileToUrl(
id: string,
): Promise<string> {
const { environment } = pluginContext
if (environment.config.command === 'serve') {
if (
environment.config.command === 'serve' &&
!environment.config.experimental.rolldownDev
) {
return fileToDevUrl(environment, id)
} else {
return fileToBuiltUrl(pluginContext, id)
Expand Down
8 changes: 7 additions & 1 deletion packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,13 @@ export function buildHtmlPlugin(config: ResolvedConfig): RolldownPlugin {
tag: 'script',
attrs: {
...(isAsync ? { async: true } : {}),
type: 'module',
...(config.experimental.rolldownDev
? {
defer: true,
}
: {
type: 'module',
}),
// crossorigin must be set not only for serving assets in a different origin
// but also to make it possible to preload the script using `<link rel="preload">`.
// `<script type="module">` used to fetch the script with credential mode `omit`,
Expand Down
27 changes: 19 additions & 8 deletions packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ export async function resolvePlugins(
normalPlugins: Plugin[],
postPlugins: Plugin[],
): Promise<Plugin[]> {
const rolldownDev = config.experimental.rolldownDev
const isBuild = config.command === 'build'
const isWorker = config.isWorker
const buildPlugins = isBuild
? await (await import('../build')).resolveBuildPlugins(config)
: { pre: [], post: [] }
const buildPlugins =
isBuild || rolldownDev
? await (await import('../build')).resolveBuildPlugins(config)
: { pre: [], post: [] }
const { modulePreload } = config.build
const depOptimizationEnabled =
!isBuild &&
Expand All @@ -60,7 +62,7 @@ export async function resolvePlugins(

return [
depOptimizationEnabled ? optimizedDepsPlugin() : null,
isBuild ? metadataPlugin() : null,
rolldownDev || isBuild ? metadataPlugin() : null,
!isWorker ? watchPackageDataPlugin(config.packageCache) : null,
!isBuild ? preAliasPlugin(config) : null,
enableNativePlugin
Expand Down Expand Up @@ -118,9 +120,18 @@ export async function resolvePlugins(
htmlInlineProxyPlugin(config),
cssPlugin(config),
config.oxc !== false
? enableNativePlugin
? nativeTransformPlugin()
: oxcPlugin(config)
? rolldownDev
? perEnvironmentPlugin(
'native:transform',
(environment) =>
nativeTransformPlugin({
reactRefresh:
environment.name === 'client' && rolldownDev?.reactRefresh,
}) as unknown as Plugin,
)
: enableNativePlugin
? nativeTransformPlugin()
: oxcPlugin(config)
: null,
enableNativePlugin
? nativeJsonPlugin({
Expand All @@ -141,7 +152,7 @@ export async function resolvePlugins(
enableNativePlugin ? nativeWasmFallbackPlugin() : wasmFallbackPlugin(),
definePlugin(config),
cssPostPlugin(config),
isBuild && buildHtmlPlugin(config),
(rolldownDev || isBuild) && buildHtmlPlugin(config),
workerImportMetaUrlPlugin(config),
assetImportMetaUrlPlugin(config),
...buildPlugins.pre,
Expand Down
Loading

0 comments on commit 679576c

Please sign in to comment.