ghost-toc

Build Instructions

This document explains how to build the minified distribution file from source.

Prerequisites

Installation

Install the development dependencies:

npm install

Build Commands

Full Build

Build the minified distribution file:

npm run build

This will:

  1. Minify src/ghost-toc.js using Terser
  2. Wrap the minified code in <script> tags
  3. Add the header comment
  4. Output to dist/ghost-toc.min.js

Clean Build Artifacts

Remove temporary build files:

npm run clean

Build Process Details

The build process consists of two steps:

1. Minification (build:minify)

Uses Terser to minify the source code:

2. Wrapping (build:wrap)

Runs scripts/wrap-script.js which:

File Structure

ghost-toc/
├── src/
│   └── ghost-toc.js          # Source code (edit this)
├── dist/
│   └── ghost-toc.min.js      # Distribution file (auto-generated)
├── scripts/
│   └── wrap-script.js        # Build wrapper script
└── package.json              # Build configuration

Development Workflow

  1. Edit src/ghost-toc.js
  2. Test locally (optional): npm run build
  3. Commit and push changes to main
  4. GitHub Actions automatically builds and commits dist/ghost-toc.min.js

Manual

  1. Make changes to src/ghost-toc.js
  2. Run npm run build to generate distribution file
  3. Test the changes using example files in examples/
  4. Commit both source and distribution files

Note: If you push to main branch, the Auto Build workflow will automatically rebuild the minified file if needed.

Manual Build (Without npm)

If you prefer not to use npm, you can manually minify:

  1. Use any JavaScript minifier (Terser, UglifyJS, etc.)
  2. Wrap the output in <script> tags
  3. Add the header comment with version from package.json:
    /* Ghost TOC v{version} | MIT License | github.com/vlavrynovych/ghost-toc */
    

Note: The automated build script reads the version from package.json, so you only need to update the version in one place.

Troubleshooting

“terser: command not found”

Make sure you’ve run npm install to install development dependencies.

Build fails on Windows

The clean script uses Unix commands. On Windows, either:

Notes