Skip to content

rewriteImportPathExtensions

Rewrites the extension of every import-like path in an emitted module’s text from .ts to the target output extension (.mjs / .cjs), so the multi-file dist/lib build references its real siblings.

Covers require('…'), static from "…", and dynamic import("…") occurrences.

Import:

import { rewriteImportPathExtensions } from '@mnaoumov/typescript-dev-toolkit/bundlers/esbuild-impl/change-extension-plugin';

Signature:

function rewriteImportPathExtensions(text: string, extension: string): string

Parameters:

Parameter Type Description
text string The emitted module text to rewrite.
extension string The output extension to rewrite .ts paths to (e.g. .mjs or .cjs).

Returns: string — The rewritten module text.