Skip to content

preprocessPlugin

Creates an esbuild plugin that preprocesses JavaScript and TypeScript files for an Obsidian plugin.

This plugin performs the following tasks: - Everything the generic preprocess plugin does (the process and Symbol.dispose shims, the sourceMappingURL fix, and the CommonJS import(dot)meta(dot)url replacement). - Falls back to activeWindow.location.href for import(dot)meta(dot)url where there is no __filename. - In a CommonJS build, patches require() so Obsidian’s built-in modules resolve and the rest degrade on mobile.

Import:

import { preprocessPlugin } from '@mnaoumov/obsidian-dev-toolkit/bundlers/esbuild-impl/preprocess-plugin';

Signature:

function preprocessPlugin(isEsm: boolean | undefined): Plugin

Parameters:

Parameter Type Description
isEsm boolean | undefined Whether the build is for an ESM format.

Returns: Plugin — An esbuild Plugin object that handles the preprocessing.