esbuild-plugin-markdown

raw JSON →
0.0.3 verified Fri May 01 auth: no javascript

An esbuild plugin that enables importing Markdown files as JavaScript modules. This v0.0.3 plugin uses the 'marked' library to parse Markdown to HTML. It exports both the raw markdown string and parsed HTML. Ideal for static site generation or content loading at build time. Compared to alternatives like '@mdx-js/esbuild', it is simpler and more lightweight but offers less transformation flexibility. The package ships with TypeScript types and is released infrequently.

error error: No loader is configured for ".md" files: ...
cause The plugin is not added to the esbuild plugins list or the import is not processed.
fix
Add markdownPlugin() to the plugins array in the esbuild build configuration.
error Cannot find module 'marked'
cause The 'marked' dependency is missing.
fix
Run npm install marked or add it to your dependencies.
error TypeError: Cannot read properties of undefined (reading 'html')
cause Importing .md file without the plugin active, resulting in undefined content.
fix
Ensure the plugin is correctly loaded and applied to esbuild.
gotcha TypeScript cannot resolve .md files unless you declare a module or include a type definition like 'declare module "*.md"'.
fix Add a .d.ts file with: declare module '*.md' { const content: { html: string; raw: string; filename: string }; export default content; }
deprecated The plugin API may change in future versions as esbuild evolves.
fix Check for updates regularly or pin version if stability needed.
npm install esbuild-plugin-markdown
yarn add esbuild-plugin-markdown
pnpm add esbuild-plugin-markdown

Bundles a JavaScript file and imports a Markdown file, parsing it with marked and enabling line breaks.

import { build } from 'esbuild';
import { markdownPlugin } from 'esbuild-plugin-markdown';

build({
  entryPoints: ['src/index.js'],
  outfile: 'dist/bundle.js',
  plugins: [
    markdownPlugin({
      markedOptions: { breaks: true }
    })
  ]
}).catch(() => process.exit(1));