micromark Build Tool

2.0.3 · active · verified Sun Apr 19

micromark-build is a small, specialized Command Line Interface (CLI) tool designed to optimize and build development source code for micromark extensions into production-ready output. It achieves this by applying a series of Babel transformations such as `babel-plugin-unassert`, `babel-plugin-undebug`, and `babel-plugin-inline-constants`. These plugins are responsible for removing development-specific assertions (like `assert` or `uvu/assert`), debug calls (from `debug`), and for inlining constant values from specified modules (e.g., `micromark-util-symbol`). This optimization process results in smaller and faster code for deployment in browser or Node.js environments. The current stable version is 2.0.3, with new releases typically coordinated within the broader micromark monorepo. Its primary differentiating factor is its tailored optimization focus specifically for the micromark ecosystem, making it an essential utility for developers creating micromark extensions who need to balance development-time debugging with production-ready performance and minimal bundle size.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart illustrates how to configure `micromark-build` in a `package.json` for a micromark extension. It shows how to define `dev/` and production `lib/` entry points using an `exports` map, and provides example development code that `micromark-build` will optimize by removing assertions and debug logs, and inlining constants.

{
  "name": "my-micromark-extension",
  "version": "1.0.0",
  "description": "My custom micromark extension.",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "build": "micromark-build"
  },
  "exports": {
    "development": "./dev/index.js",
    "default": "./index.js"
  },
  "devDependencies": {
    "micromark-build": "^2.0.0",
    "devlop": "^1.0.0",
    "micromark-util-symbol": "^2.0.0",
    "uvu": "^0.5.0"
  }
}

// Example: my-micromark-extension/dev/index.js
// (This file is processed by `micromark-build` into lib/index.js)
import { codes } from 'micromark-util-symbol';
import { assert } from 'uvu/assert';
import { debug } from 'devlop';

const log = debug('my-extension');

export function myExtension() {
  assert.ok(true, 'This assertion will be removed in production!');
  log('Debugging my extension setup.');

  return { tokenizer: { 92: onBackslash } }; // ASCII 92 is '\\'
}

function onBackslash(code) {
  log('Handling backslash character.');
  // `codes.backslash` will be inlined in production by micromark-build.
  return code === codes.backslash ? 1 : 0;
}

view raw JSON →