Skip to content

Commit

Permalink
feat: use native Vite resolver (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 19, 2024
1 parent 0330bb1 commit 07ad00f
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 62 deletions.
1 change: 1 addition & 0 deletions packages/vite/src/node/idResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function createIdResolver(
[
// @ts-expect-error the aliasPlugin uses rollup types
aliasPlugin({ entries: environment.config.resolve.alias }),
// TODO: use oxcResolvePlugin here as well
resolvePlugin({
root: config.root,
isProduction: config.isProduction,
Expand Down
12 changes: 11 additions & 1 deletion packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,19 @@ export type PluginOption = Thenable<Plugin | FalsyPlugin | PluginOption[]>

export async function resolveEnvironmentPlugins(
environment: PartialEnvironment,
): Promise<Plugin[]> {
return resolveEnvironmentPluginsRaw(
environment.getTopLevelConfig().plugins,
environment,
)
}

export async function resolveEnvironmentPluginsRaw(
plugins: readonly Plugin[],
environment: PartialEnvironment,
): Promise<Plugin[]> {
const environmentPlugins: Plugin[] = []
for (const plugin of environment.getTopLevelConfig().plugins) {
for (const plugin of plugins) {
if (plugin.applyToEnvironment) {
const applied = await plugin.applyToEnvironment(environment)
if (!applied) {
Expand Down
45 changes: 25 additions & 20 deletions packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '../plugin'
import { watchPackageDataPlugin } from '../packages'
import { jsonPlugin } from './json'
import { filteredResolvePlugin, resolvePlugin } from './resolve'
import { oxcResolvePlugin, resolvePlugin } from './resolve'
import { optimizedDepsPlugin } from './optimizedDeps'
import { importAnalysisPlugin } from './importAnalysis'
import { cssAnalysisPlugin, cssPlugin, cssPostPlugin } from './css'
Expand Down Expand Up @@ -96,25 +96,30 @@ export async function resolvePlugins(
)
: modulePreloadPolyfillPlugin(config)
: null,
enableNativePlugin
? filteredResolvePlugin({
root: config.root,
isProduction: config.isProduction,
isBuild,
packageCache: config.packageCache,
asSrc: true,
optimizeDeps: true,
externalize: true,
})
: resolvePlugin({
root: config.root,
isProduction: config.isProduction,
isBuild,
packageCache: config.packageCache,
asSrc: true,
optimizeDeps: true,
externalize: true,
}),
...(enableNativePlugin
? oxcResolvePlugin(
{
root: config.root,
isProduction: config.isProduction,
isBuild,
packageCache: config.packageCache,
asSrc: true,
optimizeDeps: true,
externalize: true,
},
isWorker ? config : undefined,
)
: [
resolvePlugin({
root: config.root,
isProduction: config.isProduction,
isBuild,
packageCache: config.packageCache,
asSrc: true,
optimizeDeps: true,
externalize: true,
}),
]),
htmlInlineProxyPlugin(config),
cssPlugin(config),
config.oxc !== false
Expand Down
Loading

0 comments on commit 07ad00f

Please sign in to comment.