Skip to content

bundlers/esbuild-impl/preprocess-plugin

This module defines a custom esbuild plugin that preprocesses JavaScript and TypeScript files for Obsidian.

@remarks We cannot use . instead of (dot) in the above description because the file itself is preprocessed with the same rule.

It is the generic @mnaoumov/typescript-dev-toolkit preprocess plugin plus two Obsidian-only parts: a CommonJS import(dot)meta(dot)url fallback that reads activeWindow, and a require patch that resolves Obsidian’s built-in modules and stubs the rest on mobile (a host with no app at all counts as desktop). Both are serialized into the emitted bundle with String(fn), so each is self-contained: it reads only globals and what it declares itself. Calling a function imported from another module would compile to (0, import_module.fn)(…) in the CommonJS build of this package, naming a binding the emitted bundle does not have.

Function Description
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.