Skip to content

Commit

Permalink
feat: use native vite resolve plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 8, 2024
1 parent 075f473 commit 3d3d4c6
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import colors from 'picocolors'
import type { PartialResolvedId, RolldownPlugin } from 'rolldown'
import { exports, imports } from 'resolve.exports'
import { hasESMSyntax } from 'mlly'
import { viteResolvePlugin } from 'rolldown/experimental'
import {
type NapiResolveOptions,
type ResolveResult,
Expand Down Expand Up @@ -337,10 +338,36 @@ function normalizeOxcResolverResult(

export function oxcResolvePlugin(
resolveOptions: ResolvePluginOptionsWithOverrides,
): [RolldownPlugin, RolldownPlugin, Plugin] {
): [RolldownPlugin, RolldownPlugin, RolldownPlugin, Plugin] {
return [
devOnlyResolvePlugin(resolveOptions),
importGlobSubpathImportsResolvePlugin(resolveOptions),
createBuiltinPluginWithEnvironmentSupport(
'vite:resolve-builtin',
(environment) => {
const options: InternalResolveOptions = {
...environment.config.resolve,
...resolveOptions, // plugin options + resolve options overrides
}

return viteResolvePlugin({
resolveOptions: {
isProduction: options.isProduction,
asSrc: options.asSrc ?? false,
preferRelative: options.preferRelative ?? false,
root: options.root,

mainFields: options.mainFields,
conditions: options.conditions,
extensions: options.extensions,
tryIndex: options.tryIndex ?? true,
tryPrefix: options.tryPrefix,
preserveSymlinks: options.preserveSymlinks,
},
environmentConsumer: environment.config.consumer,
})
},
),
createBuiltinPluginWithEnvironmentSupport('vite:resolve', (environment) => {
// The resolve plugin is used for createIdResolver and the depsOptimizer should be
// disabled in that case, so deps optimization is opt-in when creating the plugin.
Expand Down

0 comments on commit 3d3d4c6

Please sign in to comment.