Skip to main content
Version: 3x

Function: getDirname

getDirname(fileUrl): string

Converts a file:/// URL to an absolute directory path. Useful in ESM Webpack configs where __dirname is unavailable.

Parameters

NameTypeDescription
fileUrlstringThe file:/// URL of a module.

Returns

string

The directory path without the file:/// prefix.

Example

Usage in a Webpack ESM config:

import * as Repack from '@callstack/repack';

export default (env) => {
const {
context = Repack.getDirname(import.meta.url)
} = env;
};

Defined in

packages/repack/src/webpack/utils/getDirname.ts:24