{"id":14703,"library":"micromark-build","title":"micromark Build Tool","description":"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.","status":"active","version":"2.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/micromark/micromark#main","tags":["javascript","micromark","build","typescript"],"install":[{"cmd":"npm install micromark-build","lang":"bash","label":"npm"},{"cmd":"yarn add micromark-build","lang":"bash","label":"yarn"},{"cmd":"pnpm add micromark-build","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally by `micromark-build` to remove `assert`, `power-assert`, `uvu/assert`, and `devlop` calls from development code.","package":"babel-plugin-unassert","optional":false},{"reason":"Used internally by `micromark-build` to remove `debug` calls from development code, optimizing production bundles.","package":"babel-plugin-undebug","optional":false},{"reason":"Used internally by `micromark-build` to inline values from specified constant modules, such as `micromark-util-symbol`, for improved performance and reduced bundle size.","package":"babel-plugin-inline-constants","optional":false},{"reason":"This package's constants are specifically targeted and inlined by `micromark-build`. Developers of micromark extensions are encouraged to use `micromark-util-symbol` for constants to benefit from this optimization.","package":"micromark-util-symbol","optional":false}],"imports":[{"note":"This package is fundamentally a Command Line Interface (CLI) tool and is not intended for direct programmatic JavaScript/TypeScript imports. Its functionality is invoked via command-line execution, typically through an npm script.","wrong":"import { micromarkBuild } from 'micromark-build'","symbol":"micromark-build (CLI)","correct":"npm install micromark-build --save-dev\n// Then, in package.json scripts:\n\"build\": \"micromark-build\""},{"note":"While `micromark-build` processes files that can be conditionally loaded, the 'development' condition itself is a Node.js runtime flag, not a direct export from this package. Developers configure their project's `exports` map and use this flag to access unoptimized development code.","wrong":"import { development } from 'micromark-build'","symbol":"Development Condition","correct":"node --conditions development ./dev/index.js"},{"note":"`micromark-build` itself is fully typed with TypeScript but explicitly states it exports no *additional* public types for direct import. Any necessary types for developing micromark extensions, which `micromark-build` processes, would typically be imported from other `micromark-util-*` or `micromark-core-*` packages within the ecosystem.","wrong":"import type { BuildOptions } from 'micromark-build'","symbol":"TypeScript Types (related)","correct":"import type { CompileContext } from 'micromark-util-types'"}],"quickstart":{"code":"{\n  \"name\": \"my-micromark-extension\",\n  \"version\": \"1.0.0\",\n  \"description\": \"My custom micromark extension.\",\n  \"type\": \"module\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"build\": \"micromark-build\"\n  },\n  \"exports\": {\n    \"development\": \"./dev/index.js\",\n    \"default\": \"./index.js\"\n  },\n  \"devDependencies\": {\n    \"micromark-build\": \"^2.0.0\",\n    \"devlop\": \"^1.0.0\",\n    \"micromark-util-symbol\": \"^2.0.0\",\n    \"uvu\": \"^0.5.0\"\n  }\n}\n\n// Example: my-micromark-extension/dev/index.js\n// (This file is processed by `micromark-build` into lib/index.js)\nimport { codes } from 'micromark-util-symbol';\nimport { assert } from 'uvu/assert';\nimport { debug } from 'devlop';\n\nconst log = debug('my-extension');\n\nexport function myExtension() {\n  assert.ok(true, 'This assertion will be removed in production!');\n  log('Debugging my extension setup.');\n\n  return { tokenizer: { 92: onBackslash } }; // ASCII 92 is '\\\\'\n}\n\nfunction onBackslash(code) {\n  log('Handling backslash character.');\n  // `codes.backslash` will be inlined in production by micromark-build.\n  return code === codes.backslash ? 1 : 0;\n}","lang":"javascript","description":"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."},"warnings":[{"fix":"Ensure your development environment runs on Node.js v16 or higher. Always consult the `micromark` monorepo's `security.md` for the most up-to-date compatibility requirements before upgrading.","message":"Projects within the unified collective, including `micromark-build`, are only compatible with maintained versions of Node.js. Major releases typically drop support for unmaintained Node.js versions.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Only integrate `micromark-build` into projects developing or extending `micromark` functionality. For other types of JavaScript or TypeScript projects, consider widely-used bundlers or build tools like Webpack, Rollup, or esbuild.","message":"micromark-build is a highly specialized tool tailored for the `micromark` ecosystem, specifically for optimizing micromark extensions. It is not a generic JavaScript build tool and is not recommended for use outside this context.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Configure your `package.json` with an `exports` field pointing to both `development` (e.g., `./dev/index.js`) and `default` (e.g., `./index.js`) entry points. When developing, run your application or tests with `node --conditions development your-entry-file.js`.","message":"To correctly use `micromark-build` and leverage its development-time features (assertions, debug messages), you must define an `exports` map in your `package.json` with a `development` condition. To run your project using the development files, Node.js must be launched with the `--conditions development` flag.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Verify that your project structure includes a `dev/` folder containing your development source code. Ensure that `micromark-build` and its internal dependencies are correctly installed and accessible in your environment (`npm install`). Check for any syntax errors in your source files that might halt the Babel transformation.","cause":"This generic error often indicates that `micromark-build` could not find the expected `dev/` source directory, or encountered other file system or processing errors during its run.","error":"Error: Command failed with exit code 1"},{"fix":"As `micromark-build` is a CLI tool, it should not be imported or required as a programmatic module. Instead, execute it from your `package.json` scripts, for example, by adding `\"build\": \"micromark-build\"` to your `scripts` section and running `npm run build`.","cause":"These errors occur when attempting to `import` or `require` `micromark-build` directly into your JavaScript/TypeScript code.","error":"Error: Cannot find module 'micromark-build' from '...' or 'TypeError: micromarkBuild is not a function'"}],"ecosystem":"npm"}