Skip to content
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

feat: using oxc resolver #39

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"esbuild": "^0.21.3",
"postcss": "^8.4.41",
"rollup": "^4.20.0",
"rolldown": "0.12.2-snapshot-aa5807f-20240902003235"
"rolldown": "0.12.2-snapshot-aa5807f-20240902003235",
"oxc-resolver": "1.11.0"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
Expand Down
14 changes: 14 additions & 0 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,13 @@ export async function build(
ssr ? config.plugins.map((p) => injectSsrFlagToHooks(p)) : config.plugins
) as Plugin[]

const alias: Record<string, string> = {}
for (const { find, replacement } of config.resolve.alias) {
if (typeof find === 'string') {
alias[find] = replacement
}
}

const rollupOptions: RollupOptions = {
// TODO @underfin preserveEntrySignatures
// preserveEntrySignatures: ssr
Expand All @@ -541,6 +548,13 @@ export async function build(
...options.rollupOptions,
input,
plugins,
resolve: {
alias,
mainFields: config.resolve.mainFields,
conditionNames: config.resolve.conditions,
symlinks: config.resolve.preserveSymlinks,
extensions: config.resolve.extensions,
},
external: options.rollupOptions?.external,
onwarn(warning, warn) {
onRollupWarning(warning, warn, config)
Expand Down
14 changes: 12 additions & 2 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,22 @@ export async function resolveConfig(

checkBadCharactersInPath(resolvedRoot, logger)

// oxc resolver only support string alias key matching
const clientAlias = [
{
find: /^\/?@vite\/env/,
find: '/@vite/env',
replacement: path.posix.join(FS_PREFIX, normalizePath(ENV_ENTRY)),
},
{
find: /^\/?@vite\/client/,
find: '@vite/env',
replacement: path.posix.join(FS_PREFIX, normalizePath(ENV_ENTRY)),
},
{
find: '/@vite/client',
replacement: path.posix.join(FS_PREFIX, normalizePath(CLIENT_ENTRY)),
},
{
find: '@vite/client',
replacement: path.posix.join(FS_PREFIX, normalizePath(CLIENT_ENTRY)),
},
]
Expand Down Expand Up @@ -1111,6 +1120,7 @@ async function bundleConfigFile(
id,
importer,
{
alias: [],
root: path.dirname(fileName),
isBuild: true,
isProduction: true,
Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import aliasPlugin, { type ResolverFunction } from '@rollup/plugin-alias'
import { type ResolverFunction } from '@rollup/plugin-alias'
import type { ObjectHook } from 'rolldown'
import aliasPlugin from '@rollup/plugin-alias'
import type { PluginHookUtils, ResolvedConfig } from '../config'
import { isDepsOptimizerEnabled } from '../config'
import type { HookHandler, Plugin, PluginWithRequiredHook } from '../plugin'
Expand Down Expand Up @@ -58,6 +59,7 @@ export async function resolvePlugins(
: null,
resolvePlugin({
...config.resolve,
alias: config.resolve.alias,
root: config.root,
isProduction: config.isProduction,
isBuild,
Expand Down
Loading
Loading