mdpack: Markdown Bundler
mdpack is a markdown bundler that enables the composition of markdown and HTML files, treating them similarly to how JavaScript modules are imported. It processes custom `@@import` statements to combine content from various files and can output the bundled result in both markdown and HTML formats. The package, currently at version 0.5.2 (last published in August 2018), provides both a Command Line Interface (CLI) and a Node.js API for programmatic use. Key features include a plugin system, allowing extensions for tasks like HTML minification or adding banners and footers to the bundled output. While the project's README mentions alternatives like `docz` and labels its section on it as "Deprecated" (referring to `docz` or its own aspiration), `mdpack` differentiates itself through its specific custom import syntax and its dual output capabilities for markdown and HTML. Its release cadence is currently inactive, given the last publish date.
Common errors
-
Error: Cannot find module 'mdpack'
cause The `mdpack` package is not installed or not resolvable in the current project's `node_modules`.fixRun `npm install mdpack` for local installation or `npm install -g mdpack` if intending to use the CLI globally. If using `npx`, ensure it's available and configured correctly. -
mdpack: command not found
cause The `mdpack` CLI command is not available in your system's PATH, typically because it wasn't installed globally or via a local `node_modules/.bin` entry.fixInstall `mdpack` globally with `npm install -g mdpack` or use `npx mdpack` if it's a project dependency. -
Error: Unknown plugin: mdpackPluginMyCustomPlugin
cause Attempting to use a plugin that is not part of the `mdpack.plugins` namespace or has not been correctly provided/loaded.fixEnsure the plugin class is correctly imported and instantiated, and that it's a valid `mdpack` plugin. Double-check the spelling and casing of the plugin name. Custom plugins must be developed to the `mdpack` plugin API. -
Syntax Error: Unexpected token ' (or similar related to @@import)
cause Incorrect syntax used for `@@import` statements in markdown files, such as using single quotes instead of double quotes, or extra spaces.fixEnsure all `@@import` statements strictly follow the format `@@import "path/to/file.md"` with double quotes around the file path and no extraneous characters.
Warnings
- gotcha The `@@import "path/to/file"` syntax is custom to mdpack and not standard Markdown. Using standard Markdown includes or common templating syntaxes will not work.
- gotcha The package (version 0.5.2) was last published in August 2018, indicating it may not be actively maintained. This could lead to compatibility issues with newer Node.js versions, outdated dependencies, or potential security vulnerabilities.
- gotcha The README contains a section titled 'Deprecated' that refers to 'docz'. This phrasing can be ambiguous and lead users to believe `mdpack` itself is deprecated, rather than clarifying its relation to `docz` or its own aspirations. `mdpack` is not explicitly marked as deprecated by its author.
- gotcha The project uses CommonJS (`require`) exclusively in its examples and was released before widespread Node.js ESM adoption. Using `import` statements directly might require a build step (like Babel or Webpack) or specific Node.js `--experimental-modules` flags, which might not be supported or stable for this older package.
Install
-
npm install mdpack -
yarn add mdpack -
pnpm add mdpack
Imports
- mdpack
const { mdpack } = require('mdpack')import mdpack from 'mdpack'
- mdpackPluginHtmlMinifier
import { mdpackPluginHtmlMinifier } from 'mdpack'import mdpack from 'mdpack'; new mdpack.plugins.mdpackPluginHtmlMinifier()
- mdpackPluginBannerFooter
new mdpackPluginBannerFooter()
import mdpack from 'mdpack'; new mdpack.plugins.mdpackPluginBannerFooter({ banner: '# Banner' })
Quickstart
const path = require('path');
const mdpack = require('mdpack');
const config = {
entry: 'index.md',
output: {
path: path.resolve(__dirname, 'dist'),
name: 'mybundle'
},
format: ['md', 'html'],
resources: {
markdownCss: 'https://unpkg.com/github-markdown-css@2.10.0/github-markdown.css',
highlightCss: 'https://unpkg.com/highlight.js@9.12.0/styles/github-gist.css'
},
template: path.resolve(__dirname, 'mytemplate.html'),
plugins: [
new mdpack.plugins.mdpackPluginHtmlMinifier(),
new mdpack.plugins.mdpackPluginBannerFooter({
banner: '# My Custom Banner',
footer: '<footer>Built with mdpack</footer>'
})
],
watch: false // Set to true for development
};
// Create dummy files for the example to run
require('fs').writeFileSync('index.md', '# Hello World\n\n@@import "./sub.md"');
require('fs').writeFileSync('sub.md', '## Sub-content here');
require('fs').writeFileSync('mytemplate.html', '<!DOCTYPE html><html><head><title>My Bundle</title></head><body><div class="markdown-body">{html}</div></body></html>');
mdpack(config).then(() => console.log('mdpack bundled successfully!')).catch(err => console.error('mdpack error:', err));