Skip to content
Merged
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: 3 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export {
defineConfig,
type LoadConfigOptions,
type LoadConfigResult,
type RsbuildConfigAsyncFn,
type RsbuildConfigDefinition,
type RsbuildConfigSyncFn,
loadConfig,
} from './loadConfig';
// Core methods
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type RsbuildConfigAsyncFn = (env: ConfigParams) => Promise<RsbuildConfig>

export type RsbuildConfigSyncFn = (env: ConfigParams) => RsbuildConfig;

export type RsbuildConfigExport = RsbuildConfig | RsbuildConfigSyncFn | RsbuildConfigAsyncFn;
export type RsbuildConfigDefinition = RsbuildConfig | RsbuildConfigSyncFn | RsbuildConfigAsyncFn;
Comment thread
chenjiahan marked this conversation as resolved.

export type LoadConfigOptions = {
/**
Expand Down Expand Up @@ -77,8 +77,8 @@ export type LoadConfigResult = {
export function defineConfig(config: RsbuildConfig): RsbuildConfig;
export function defineConfig(config: RsbuildConfigSyncFn): RsbuildConfigSyncFn;
export function defineConfig(config: RsbuildConfigAsyncFn): RsbuildConfigAsyncFn;
export function defineConfig(config: RsbuildConfigExport): RsbuildConfigExport;
export function defineConfig(config: RsbuildConfigExport) {
export function defineConfig(config: RsbuildConfigDefinition): RsbuildConfigDefinition;
export function defineConfig(config: RsbuildConfigDefinition) {
return config;
}

Expand Down Expand Up @@ -115,10 +115,10 @@ const resolveConfigPath = (root: string, customConfig?: string) => {

export type ConfigLoader = 'auto' | 'jiti' | 'native';

const getConfigExport = (module: unknown): RsbuildConfigExport =>
const getConfigExport = (module: unknown): RsbuildConfigDefinition =>
(module && typeof module === 'object' && 'default' in module
? module.default
: module) as RsbuildConfigExport;
: module) as RsbuildConfigDefinition;

const tryFreshImport = async (configFileURL: string) => {
try {
Expand All @@ -133,7 +133,7 @@ const tryFreshImport = async (configFileURL: string) => {
const loadConfigWithNative = async (
configFilePath: string,
): Promise<{
configExport: RsbuildConfigExport;
configExport: RsbuildConfigDefinition;
dependencies: string[];
}> => {
const configFileURL = pathToFileURL(configFilePath).href;
Expand Down Expand Up @@ -179,7 +179,7 @@ export async function loadConfig({
return config;
};

let configExport: RsbuildConfigExport | undefined;
let configExport: RsbuildConfigDefinition | undefined;

// Determine the loading strategy based on the config loader type
const useNative = Boolean(
Expand Down Expand Up @@ -215,7 +215,7 @@ export async function loadConfig({
nativeModules: ['typescript'],
});

configExport = await jiti.import<RsbuildConfigExport>(configFilePath, {
configExport = await jiti.import<RsbuildConfigDefinition>(configFilePath, {
default: true,
});
} catch (err) {
Expand Down
Loading