Skip to content

replaceDefines

Replaces each compile-time constant in a module’s code with its value, as a bundler’s define does: only where the whole expression stands on its own, so process.env.NODE_ENV is replaced and a.process.env.NODE_ENV or process.env.NODE_ENV_X are not.

Import:

import { replaceDefines } from '@mnaoumov/obsidian-dev-toolkit/bundlers/obsidian-plugin-features';

Signature:

function replaceDefines(code: string, defines: Readonly<Record<string, string>>): string

Parameters:

Parameter Type Description
code string The module’s code.
defines Readonly<Record<string, string>> The constants, by expression, each value a JavaScript literal.

Returns: string — The code with the constants replaced.