Resolver API

Rspack 使用 Rust 编写的更高性能的 rspack-resolver 来代替 Webpack 中的 enhanced-resolve,并通过 rspack.experiments.resolver 实验性地重导出了这些 API。这使你能够直接调用 rspack-resolver 的 resolver.syncresolver.async 等功能。

完整的用法以及选项参见 rspack-resolver,以下是一个简单的示例,演示如何使用 Rspack 解析模块的路径:

import { rspack } from '@rspack/core';

const { resolver } = rspack.experiments;

// 直接使用默认选项的 Resolver API
const { path: resolvedPath } = resolver.sync(contextPath, './index.js');
const { path: resolvedPath } = await resolver.async(contextPath, './index.js');

// 使用 ResolverFactory 自定义选项
const customResolver = new resolver.ResolverFactory(resolveOptions);
const result = customResolver.sync(contextPath, './request.js');
const result = await customResolver.async(contextPath, './request.js');